Skip to content

About

The AntelopeJS contract for HTTP and WebSocket APIs. Declare controllers and routes with decorators and let the implementing module serve them.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

2 stars

Watchers

2 watching

Forks

Latest commit

 

History

101 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

INTERFACE · API: part of AntelopeJS, hexagonal architecture beyond your own code. A glowing button reads Star AntelopeJS.

@antelopejs/interface-api

npm License Discord Docs Star AntelopeJS

The AntelopeJS contract for HTTP and WebSocket APIs. Declare controllers and routes with decorators and let the implementing module serve them.

Documentation · Implementations · All interfaces and providers

What it offers

  • Controller and PartialController group routes under a base path, with nesting through extend.
  • @Get, @Post, @Put, @Delete, and @Route map methods to endpoints. @Prefix, @Postfix, and @Monitor run before or after them.
  • @Parameter, @MultiParameter, @JSONBody, @RawBody, @BodyStream, @Context, @Result, and @WriteStream inject request data into handler arguments. @Transform changes a value before the handler receives it.
  • HTTPResult sets the status, headers, and body of a response. The body is an HTTPBody, which is a string or a value that JSON.stringify writes as JSON.
  • @WebsocketHandler and @Connection handle 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

Part of AntelopeJS

AntelopeJS is the TypeScript framework where modules depend on contracts and the application chooses the provider. AntelopeJS DMS is built on it.

Area Contracts Providers
API interface-api · interface-api-util · interface-data-api api
Auth interface-auth auth-jwt
Database interface-database · interface-database-decorators · interface-database-catalog · interface-mongodb · interface-rethinkdb postgres · mongodb · rethinkdb
Redis interface-redis · interface-redis-scheduler redis
Email interface-email nodemailer · brevo
File storage interface-file-storage file-storage-local · file-storage-s3
Payments interface-payment · interface-subscriptions · interface-stripe stripe · mollie · checkout-com · payment-subscriptions

License

Apache-2.0

About

The AntelopeJS contract for HTTP and WebSocket APIs. Declare controllers and routes with decorators and let the implementing module serve them.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

2 stars

Watchers

2 watching

Forks

Releases

Used by

Contributors

Languages