Registry / web-framework / fets
library0.5.3jsnpmunverified

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.

npm install fets
INSTALL
IMPORT
SIG · FETS
F
fets
web-frameworkjavascriptv0.5.3
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

createServer
import { createServer } from 'fets'
const { createServer } = require('fets')
feTS is primarily an ESM-first library, especially for Node.js >=16.0.0 environments. Avoid CommonJS `require` syntax.
createRouter
import { createRouter } from 'fets'
import createRouter from 'fets/router'
Routes are typically created using `createRouter` and integrated with `createServer`.
Type
import { Type } from '@sinclair/typebox'
TypeBox's `Type` object is fundamental for defining schemas for requests, responses, and parameters, enabling type-safety and validation.

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'); });
fets --version
Debug
Known issues
breakingPreviously, the OpenAPI plugin hardcoded `requestBody.required = true` for all JSON and formData request bodies, even if they were defined as optional using TypeBox's `Type.Optional` modifier. This meant that clients making requests without a body to an endpoint expecting an optional body would still receive a validation error indicating a missing body.
fix
Upgrade to `fets@0.8.6` or higher to correctly respect `Type.Optional` for request bodies in OpenAPI spec generation and validation. Ensure your TypeBox schemas accurately reflect whether a request body is truly optional.
affects: <0.8.6
breakingVersion 0.8.1 introduced more strict typing on request parameters. Existing code that previously passed type checks for request parameters (path, query, headers, body) might now yield TypeScript errors if the types are not precisely aligned with the defined TypeBox schemas.
fix
Review and update your TypeBox schemas and the types used in your route handlers to match the stricter parameter typing. Ensure all request parameters strictly conform to their schema definitions.
affects: >=0.8.1
gotchafeTS is designed for modern Node.js environments (>=16.0.0) and largely expects an ESM (ECMAScript Modules) setup. Using CommonJS `require()` syntax for imports can lead to `ReferenceError: require is not defined` or similar module resolution issues.
fix
Ensure your project is configured for ESM. Use `import` statements for all feTS modules and ensure your `package.json` includes `"type": "module"` or uses `.mjs` file extensions for your source files.
affects: >=0.7.0
Errors
Common errors & fixes
ReferenceError: require is not defined
Attempting to use CommonJS `require()` syntax in a feTS project, which is typically configured for ESM.
fix
Change `const { symbol } = require('package')` to `import { symbol } from 'package'` for all module imports. Ensure your `package.json` has `"type": "module"`.
Argument of type '...' is not assignable to parameter of type '...' (TypeScript error)
Mismatch between the data structure provided to a feTS route handler (e.g., body, params) or returned from it, and the TypeBox schema defined for that route.
fix
Carefully review your TypeBox schemas and the corresponding TypeScript types in your route handlers. Ensure that the shapes of the data being sent, received, or returned precisely match the defined schemas.
Request body is required but not provided (during OpenAPI validation or client request)
Sending a request to an endpoint with a TypeBox schema that defines the request body as `Type.Object(...)` without `Type.Optional(...)` wrapper, but the request does not include a body.
fix
If the request body is genuinely optional, ensure your TypeBox schema for the request body is wrapped with `Type.Optional(Type.Object(...))` and you are on `fets@0.8.6` or higher. Otherwise, provide the required request body in your client request.
Upgrade
Version history
0.5.3latest on npm
Audit
Dependencies
@whatwg-node/serverrequiredCore HTTP server implementation, providing the underlying Web Fetch API compatible server environment.
@sinclair/typeboxrequiredUsed for defining JSON schemas, which are critical for runtime validation, type inference, and OpenAPI specification generation.
Agent activity
4 hits · last 30 days
node
4
Resources
fets — npm install fets · libregistry