feTS HTTP Framework

0.8.6 · active · verified Sun Apr 19

feTS (Fetch API + TypeScript) is a modern TypeScript HTTP framework designed for building performant and type-safe REST APIs. It prioritizes end-to-end type-safety, ease of setup, and a superior developer experience by leveraging the Web Fetch API standards. The framework is currently stable at version 0.8.6 and maintains an active development pace with frequent patch releases and minor version updates every few months, incorporating bug fixes, dependency upgrades, and new features. A key differentiator is its deep integration with TypeScript, coupled with `@sinclair/typebox` for defining robust schemas. This approach enables automatic runtime validation and OpenAPI specification generation, significantly reducing common API development pitfalls and ensuring consistent type adherence across the entire application stack, from client to server. It's built for Node.js environments and requires version 16.0.0 or higher.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates creating a basic feTS server with a GET route using path parameters and a POST route with a JSON body, showcasing TypeBox schema integration for type-safety and validation.

import { createServer, createRouter, Response } from 'fets';
import { Type } from '@sinclair/typebox';

const userSchema = Type.Object({
  id: Type.String(),
  name: Type.String(),
});

const router = createRouter()
  .get(
    '/greet/:name',
    {
      parameters: Type.Object({
        name: Type.String({ description: 'The name to greet' }),
      }),
      responses: {
        200: Type.String(),
      },
    },
    ({ params }) => Response.json(`Hello, ${params.name}!`)
  )
  .post(
    '/users',
    {
      body: userSchema,
      responses: {
        201: userSchema,
      },
    },
    async ({ body }) => {
      console.log('Received user:', body);
      // In a real app, you'd save this to a database
      return new Response(JSON.stringify({ ...body, id: 'new-id-' + Math.random().toString(36).substring(7) }), {
        status: 201,
        headers: { 'Content-Type': 'application/json' },
      });
    }
  );

const server = createServer({
  router,
});

server.listen(4000, () => {
  console.log('feTS server running on http://localhost:4000');
  console.log('Try: curl http://localhost:4000/greet/World');
  console.log('Try: curl -X POST -H "Content-Type: application/json" -d \'{"name":"Alice"}\' http://localhost:4000/users');
});

view raw JSON →