UNPKG

typescript-rest

Version:
79 lines (78 loc) 2.11 kB
/// <reference types="express" /> import * as express from 'express'; /** * The supported HTTP methods. */ export declare enum HttpMethod { GET = 0, POST = 1, PUT = 2, DELETE = 3, HEAD = 4, OPTIONS = 5, PATCH = 6, } /** * Represents the current context of the request being handled. */ export declare class ServiceContext { /** * The resolved language to be used in the current request handling. */ language: string; /** * The preferred media type to be used in the current request handling. */ accept: string; /** * The request object. */ request: express.Request; /** * The response object */ response: express.Response; /** * The next function. It can be used to delegate to the next middleware * registered the processing of the current request. */ next: express.NextFunction; } /** * The Base class for all HTTP errors */ export declare abstract class HttpError extends Error { statusCode: number; message: string; constructor(name: string, statusCode: number, message: string); } /** * Used to create a reference to a resource. */ export declare abstract class ReferencedResource<T> { location: string; statusCode: number; body: T; /** * Constructor. Receives the location of the resource. * @param location To be added to the Location header on response * @param statusCode the response status code to be sent * @param body the body to be sent */ constructor(location: string, statusCode: number, body?: T); } /** * The factory used to instantiate the object services */ export interface ServiceFactory { /** * Create a new service object. Called before each request handling. */ create: (serviceClass: Function) => any; /** * Return the type used to handle requests to the target service. * By default, returns the serviceClass received, but you can use this * to implement IoC integrations. */ getTargetClass: (serviceClass: Function) => FunctionConstructor; }