0.3.0 • Published 12 months ago

@wooksjs/fastify-adapter v0.3.0

Weekly downloads
-
License
MIT
Repository
github
Last release
12 months ago

Fastify Adapter (Wooks Composables)

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

Want to use @wooksjs/event-http but your project is coupled with fastify? ✅ This is not a problem with this Fastify Adapter for wooks

Install

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

Usage

import fastify from 'fastify'
import { applyFastifyAdapter } from '@wooksjs/fastify-adapter'
import { useBody } from '@wooksjs/http-body'
import { WooksError } from '@wooksjs/event-http'
import { useRouteParams } = from '@wooksjs/event-core'

const app = fastify()

applyFastifyAdapter(app)

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

app.post('/post', () => {
    const { parseBody } = useBody()
    return parseBody()
})

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

app.listen(3000, () => console.log('listening 3000'))