@wooksjs/h3-adapter
TypeScript icon, indicating that this package has built-in type declarations

0.1.0 • Public • Published

H3 Adapter (Wooks Composables)

!!! This is work-in-progress library, breaking changes are expected !!!


🔥 Get power of @wooksjs/event-http in your h3 project!

Install

npm install @wooksjs/h3-adapter @wooksjs/event-http

Usage

import { WooksError, useRequest} from '@wooksjs/event-http'
import { useRouteParams} from '@wooksjs/event-core'
import { useBody } from '@wooksjs/http-body'
import { useProxy } from '@wooksjs/http-proxy'
import { createServer } from 'http'
import { createApp, toNodeListener, createRouter  } from 'h3'
import { eventHandler } from '@wooksjs/h3-adapter'

const router = createRouter()

router.get('/test/:param', eventHandler(() => {
    const { get } = useRouteParams()
    return { message: 'it works', param: get('param'), url: useRequest().url }
}))

router.post('/post', eventHandler(async () => {
    const { parseBody, rawBody } = useBody()
    const raw = await rawBody()
    return { parsed: await parseBody(), raw  }
}))

router.get('/error', eventHandler(() => {
    throw new WooksError(400, 'test error')
}))

router.get('/proxy', eventHandler(() => {
    const proxy = useProxy()
    return proxy('http://localhost:3000/test/proxy')
}))

const app = createApp()
app.use(router)

createServer(toNodeListener(app))
    .listen(process.env.PORT || 3000, () => console.log('listening 3000'))

Package Sidebar

Install

npm i @wooksjs/h3-adapter

Weekly Downloads

1

Version

0.1.0

License

MIT

Unpacked Size

6.36 kB

Total Files

6

Last publish

Collaborators

  • mav-rik