HTTP Decorators
Exhaustive list of HTTP decorators provided by ts-basis/nodejs
Table of Contents
HTTP Decorators
GET Decorator
- Usage:
@HTTP.GET('/path') - Purpose: Register a handler for HTTP GET requests to a specific path.
POST Decorator
- Usage:
@HTTP.POST('/path') - Purpose: Register a handler for HTTP POST requests to a specific path.
PATCH Decorator
- Usage:
@HTTP.PATCH('/path') - Purpose: Register a handler for HTTP PATCH requests to a specific path.
PUT Decorator
- Usage:
@HTTP.PUT('/path') - Purpose: Register a handler for HTTP PUT requests to a specific path.
DELETE Decorator
- Usage:
@HTTP.DELETE('/path') - Purpose: Register a handler for HTTP DELETE requests to a specific path.
CRUD Decorator
- Usage:
@HTTP.CRUD('/path') - Purpose: Register handlers for all CRUD operations (POST, GET, PATCH, PUT, DELETE) to a specific path. Works with datastore backend with CRUD support for doing CRUD operations on data entity with known unique path.
METHODS Decorator
- Usage:
@HTTP.METHODS([HttpMethod.GET, HttpMethod.POST], '/path') - Purpose: Register handlers for multiple HTTP methods to a specific path.
ACCESS Decorator
- Usage:
@HTTP.ACCESS({ ADMIN: true }) - Purpose: Define access control for an API method based on roles.
Function Documentation
Request Class
- Attributes:
op: Operation instance.oriReq: Original Express or Fastify request objectheaders: Request headers.params: URL parameters.body: Request body as a string.
- Methods:
getHeader(headerName: string): Retrieves a specific header value.
Response Class
- Attributes:
op: Operation instance.oriReq: Original Express or Fastify request objectoriRes: Original Express or Fastify response objectheaders: Response headers.statusCode: HTTP status code for the response.
- Methods:
send(payload: string): Sends a response with the given payload.end(payload: string): Ends the response with the given payload.