@antelopejs/interface-api
The AntelopeJS interface for HTTP and WebSocket APIs. You declare controllers and routes with decorators, and the module that implements the interface serves them.
Part of AntelopeJS. Used by AntelopeJS DMS, the open-source back office for your PostgreSQL, MongoDB or RethinkDB database.
What it offers
ControllerandPartialControllergroup routes under a base path, with nesting throughextend.@Get,@Post,@Put,@Delete, and@Routemap methods to endpoints.@Prefix,@Postfix, and@Monitorrun before or after them.@Parameter,@MultiParameter,@JSONBody,@RawBody,@BodyStream,@Context,@Result, and@WriteStreaminject request data into handler arguments.@Transformchanges a value before the handler receives it.HTTPResultsets the status, headers, and body of a response. The body is anHTTPBody, which is a string or a value thatJSON.stringifywrites as JSON.@WebsocketHandlerand@Connectionhandle WebSocket connections on the same controllers.
Implementations
| Module | Notes |
|---|---|
@antelopejs/api | HTTP and WebSocket server, CORS settings |
Install
Add the interface to the module that declares routes:
pnpm add @antelopejs/interface-api
Then add an implementation to the project:
ajs project modules add @antelopejs/api
Quick start
import {
Controller,
Get,
HTTPResult,
JSONBody,
Parameter,
Post,
} from "@antelopejs/interface-api";
export class BookController extends Controller("/books") {
@Get(":id")
async getBook(@Parameter("id") id: string) {
return new HTTPResult(200, { id });
}
@Post("")
async createBook(@JSONBody() body: { title: string }) {
return new HTTPResult(201, body);
}
}
The decorators register the routes when JavaScript defines the class. @antelopejs/api serves GET /books/:id and POST /books.
Documentation
Compatibility
The module declares this peer dependency:
| Package | Supported | Tested with |
|---|---|---|
@antelopejs/interface-core | >=0.4.0 <1.0.0 | 0.4.0 |
Contributing
Read CONTRIBUTING.md before you open a pull request. The local checks are:
pnpm install
pnpm run checks