The API

22.10.2 · active · verified Wed Apr 22

The API (the-api) is a comprehensive JavaScript/TypeScript framework designed for rapidly building RESTful APIs. Currently at version 22.10.2, it appears to follow a relatively frequent release cadence, indicated by its high major version number. It differentiates itself by providing a robust set of features out-of-the-box, including flexible routing (leveraging Hono under the hood for context handling), automatic CRUD generation for database tables, powerful validation mechanisms, role-based access control, and a rich ecosystem of built-in middlewares for common tasks like CORS, logging, and error handling. The framework supports both Node.js (version 18 and above) and Bun runtimes, and ships with full TypeScript type definitions, enabling a strong development experience. Its design emphasizes convention over configuration, aiming to minimize boilerplate while still offering deep customization capabilities for various API needs.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to set up a basic The API server with a GET route using path parameters.

import { Routings, TheAPI, middlewares } from 'the-api';

const router = new Routings();

// Define a GET route with a path parameter
router.get('/data/:id', async (c) => {
  const { id } = c.req.param();        // Extract route parameter 'id'
  // Simulate an async operation, e.g., fetching from a DB
  await new Promise(resolve => setTimeout(resolve, 50));
  c.set('result', { id, foo: 'bar', timestamp: new Date().toISOString() }); // Set response result
});

// Initialize TheAPI with common middlewares and our defined router
const theAPI = new TheAPI({ routings: [middlewares.common, router] });

// Start the server (using top-level await)
try {
  await theAPI.up(); // For Node.js
  console.log('TheAPI server started on http://localhost:7788');
  // For Bun, you would typically export the result of theAPI.upBun();
  // export default await theAPI.upBun();
} catch (error) {
  console.error('Failed to start TheAPI server:', error);
  process.exit(1);
}

view raw JSON →