Cloudflare Workers

Cloudflare Workers 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

npm i fets

Example with Service Worker API

You can use feTS as an event listener for the Service Worker API 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 } } }, 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.

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 } } }, handler: () => Response.json({ message: 'Hello World!' }) })
 
export default {
  fetch: router.fetch
}