Cloudflare Workers
Cloudflare Workers (opens in a new tab) provides a serverless execution environment that allows you to create entirely new applications or augment existing ones without configuring or maintaining infrastructure.
feTS provides you a cross-platform HTTP Server, so it is really easy to integrate feTS into CloudFlare Workers as well.
Installation
Terminal
yarn add fets
Example with Service Worker API
You can use feTS as an event listener for the Service Worker API (opens in a new tab) in Cloudflare Workers.
import { createRouter, Response } from 'fets'
const router = createRouter<FetchEvent>().route({
method: 'GET',
path: '/greetings',
schemas: {
responses: {
200: {
type: 'object',
properties: {
message: {
type: 'string'
}
},
required: ['message'],
additionalProperties: false
}
}
} as const,
handler: () => Response.json({ message: 'Hello World!' })
})
self.addEventListener('fetch', router)
Example with Module Workers API
You can use feTS with Module Workers. See the difference here (opens in a new tab).
import { createRouter, Response } from 'fets'
const router = createRouter().route({
method: 'GET',
path: '/greetings',
schemas: {
responses: {
200: {
type: 'object',
properties: {
message: {
type: 'string'
}
},
required: ['message'],
additionalProperties: false
}
}
} as const,
handler: () => Response.json({ message: 'Hello World!' })
})
export default {
fetch: router.fetch
}