An experimental lightweight worker version of Fastify.
Currently Cloudflare Workers and Bun are supported.
npm i fastify-edge --saveimport FastifyEdge from 'fastify-edge/bun'
const app = FastifyEdge();
app.get('/', (_, reply) => {
reply.send('Hello World')
})
export default app;See examples/bun.
import FastifyEdge from 'fastify-edge'
const app = FastifyEdge()
app.get('/', (_, reply) => {
reply.send('Hello World')
})See examples/cloudflare with miniflare.
app.addHook('onSend', (req, reply, payload) => {
if (req.url === '/') {
return `${payload} World!`
}
})
app.get('/redirect', (_, reply) => {
reply.redirect('/')
})
app.get('/route-hook', {
onRequest (_, reply) {
reply.send('<b>Content from onRequest hook</b>')
},
handler (_, reply) {
reply.type('text/html')
}
})app.addHook(hook, function)app.route(settings)app.get(path, handlerOrSettings)app.post(path, handlerOrSettings)app.put(path, handlerOrSettings)app.delete(path, handlerOrSettings)app.options(path, handlerOrSettings)
|
|
Returns the request URL path ( |
|
|
Returns the request URL origin (e.g., |
|
|
Returns the request URL hostname (e.g., |
|
|
Returns the request URL protocol (e.g., |
|
|
Maps to the |
|
|
The consumed body following the parsing pattern from this example. |
|
|
The parsed route params from the internal Radix-tree router, radix3. |
|
|
Maps to the |
|
|
The raw |
|
|
Sets the |
|
|
Adds an individual header to the |
|
|
Adds multiple headers to the |
|
|
Retrieves an individual header from |
|
|
Retrieves all headers from |
|
|
Remove an individual header from |
|
|
Asserts presence of an individual header in the |
|
|
Sets the |
|
|
Sets the |
|
|
Sets the Can be a string, an object, a buffer or a stream. Objects are automatically serialized as JSON. |
The original Fastify
onRequest,
onSend and
onResponse are supported.
Diverging from Fastify, they're all treated as async functions.
They can be set at the global and route levels.
- No support for
preHandler,preParsingandpreValdationhooks. - No support for Fastify's plugin system (yet).
- No support for Fastify's logging and validation facilities.
- Still heavily experimental, more equivalent APIs coming soon.