ServerComparison

Comparison

itty-router

itty-router is a very thin router library that allows you to define routes and handlers based on Fetch API just like feTS does.

More optimized Fetch API for Node.js

feTS uses a better optimized version of Fetch API for Node.js as you can see here the differences between the Fetch impl feTS uses and the default one in Node.js.

No need to implement an adapter for Node.js

If you want to use itty-router in Node.js, you need to implement an adapter Node.js’s server API because Node’s HTTP package doesn’t use Fetch API like Deno or Bun does. itty-router is designed to be used with Fetch-compliant environments like Deno, Bun or Cloudflare Workers, so it doesn’t aim to support Node.js.

feTS uses an adapter layer @whatwg-node/server that allows you to use Fetch API in Node.js’s http library. So you don’t need to implement an adapter for Node.js.

Plugin system

feTS has a plugin system that allows you to extend the functionality of the router. This allows us to hook different phases of the request lifecycle and add new features to the router. For example, you can manipulate the response after the handler resolves. In itty-router, you need to wrap the router’s fetch method to do that.

import { Router } from "itty-router";
 
const router = Router();
 
router.get("/hello", () => new Response("Hello World!"));
 
const wrappedFetch = (request: Request) => {
  const response = await router.fetch(request);
  // Do something with the response here
  logResponse(response);
  // Manipulate the response here
  response.headers.set("X-Hello", "World");
  return response;
};

But in feTS;

import { createRouter } from 'fets'
 
const router = createRouter({
  plugins: [
    {
      onResponse({ response }) {
        // Do something with the response here
        logResponse(response)
        // Manipulate the response here
        response.headers.set('X-Hello', 'World')
      }
    }
  ]
})

On the other hand, even if you can manipulate the request, return an early response for the missing auth params etc. but a plugin system usually makes things easier.

Type Safe Route handlers

feTS allows you to define type-safe route handlers in most cases even if a schema is not defined.

import { createRouter } from 'fets'
 
const router = createRouter().route({
  method: 'GET',
  path: '/user/:id',
  handler: req => {
    // req.params.id is type safe
    // req.params.name would be an error in TypeScript
    return new Response(`Hello ${req.params.id}`)
  }
})

Out-of-box support for JSON Schema and OpenAPI

feTS has out-of-box support for JSON Schema and OpenAPI. You can define a schema for your routes and feTS will validate the request and response against the schema. And you can generate OpenAPI documentation from your routes.

Learn more about validations

Learn more about OpenAPI