typescript-rest
Version:
A Library to create RESTFul APIs with Typescript
539 lines (538 loc) • 12.5 kB
TypeScript
import 'reflect-metadata';
/**
* A decorator to tell the [[Server]] that a class or a method
* should be bound to a given path.
*
* For example:
*
* ```
* @ Path('people')
* class PeopleService {
* @ PUT
* @ Path(':id')
* savePerson(person:Person) {
* // ...
* }
*
* @ GET
* @ Path(':id')
* getPerson():Person {
* // ...
* }
* }
* ```
*
* Will create services that listen for requests like:
*
* ```
* PUT http://mydomain/people/123 or
* GET http://mydomain/people/123
* ```
*/
export declare function Path(path: string): (...args: any[]) => any;
/**
* A decorator to tell the [[Server]] that a class or a method
* should only accept requests from clients that accepts one of
* the supported languages.
*
* For example:
*
* ```
* @ Path('accept')
* @ AcceptLanguage('en', 'pt-BR')
* class TestAcceptService {
* // ...
* }
* ```
*
* Will reject requests that only accepts languages that are not
* English or Brazilian portuguese
*
* If the language requested is not supported, a status code 406 returned
*/
export declare function AcceptLanguage(...languages: string[]): (...args: any[]) => any;
/**
* A decorator to tell the [[Server]] that a class or a method
* should only accept requests from clients that accepts one of
* the supported mime types.
*
* For example:
*
* ```
* @ Path('accept')
* @ Accept('application/json')
* class TestAcceptService {
* // ...
* }
* ```
*
* Will reject requests that only accepts mime types that are not
* 'application/json'
*
* If the mime type requested is not supported, a status code 406 returned
*/
export declare function Accept(...accepts: string[]): (...args: any[]) => any;
/**
* A decorator to be used on class properties or on service method arguments
* to inform that the decorated property or argument should be bound to the
* [[ServiceContext]] object associated to the current request.
*
* For example:
*
* ```
* @ Path('context')
* class TestService {
* @ Context
context: ServiceContext;
* // ...
* }
* ```
*
* The field context on the above class will point to the current
* [[ServiceContext]] instance.
*/
export declare function Context(...args: any[]): any;
/**
* A decorator to be used on class properties or on service method arguments
* to inform that the decorated property or argument should be bound to the
* the current request.
*
* For example:
*
* ```
* @ Path('context')
* class TestService {
* @ ContextRequest
request: express.Request;
* // ...
* }
* ```
*
* The field request on the above class will point to the current
* request.
*/
export declare function ContextRequest(...args: any[]): any;
/**
* A decorator to be used on class properties or on service method arguments
* to inform that the decorated property or argument should be bound to the
* the current response object.
*
* For example:
*
* ```
* @ Path('context')
* class TestService {
* @ ContextResponse
response: express.Response;
* // ...
* }
* ```
*
* The field response on the above class will point to the current
* response object.
*/
export declare function ContextResponse(...args: any[]): any;
/**
* A decorator to be used on class properties or on service method arguments
* to inform that the decorated property or argument should be bound to the
* the next function.
*
* For example:
*
* ```
* @ Path('context')
* class TestService {
* @ ContextNext
* next: express.NextFunction
* // ...
* }
* ```
*
* The next function can be used to delegate to the next registered
* middleware the current request processing.
*/
export declare function ContextNext(...args: any[]): any;
/**
* A decorator to be used on class properties or on service method arguments
* to inform that the decorated property or argument should be bound to the
* the current context language.
*
* For example:
*
* ```
* @ Path('context')
* class TestService {
* @ ContextLanguage
* language: string
* // ...
* }
* ```
*/
export declare function ContextLanguage(...args: any[]): any;
/**
* A decorator to be used on class properties or on service method arguments
* to inform that the decorated property or argument should be bound to the
* the preferred media type for the current request.
*
* For example:
*
* ```
* @ Path('context')
* class TestService {
* @ ContextAccept
* media: string
* // ...
* }
* ```
*/
export declare function ContextAccept(...args: any[]): any;
/**
* A decorator to tell the [[Server]] that a method
* should be called to process HTTP GET requests.
*
* For example:
*
* ```
* @ Path('people')
* class PeopleService {
* @ GET
* getPeople() {
* // ...
* }
* }
* ```
*
* Will create a service that listen for requests like:
*
* ```
* GET http://mydomain/people
* ```
*/
export declare function GET(target: any, propertyKey: string, descriptor: PropertyDescriptor): void;
/**
* A decorator to tell the [[Server]] that a method
* should be called to process HTTP POST requests.
*
* For example:
*
* ```
* @ Path('people')
* class PeopleService {
* @ POST
* addPerson() {
* // ...
* }
* }
* ```
*
* Will create a service that listen for requests like:
*
* ```
* POST http://mydomain/people
* ```
*/
export declare function POST(target: any, propertyKey: string, descriptor: PropertyDescriptor): void;
/**
* A decorator to tell the [[Server]] that a method
* should be called to process HTTP PUT requests.
*
* For example:
*
* ```
* @ Path('people')
* class PeopleService {
* @ PUT
* @ Path(':id')
* savePerson(person: Person) {
* // ...
* }
* }
* ```
*
* Will create a service that listen for requests like:
*
* ```
* PUT http://mydomain/people/123
* ```
*/
export declare function PUT(target: any, propertyKey: string, descriptor: PropertyDescriptor): void;
/**
* A decorator to tell the [[Server]] that a method
* should be called to process HTTP DELETE requests.
*
* For example:
*
* ```
* @ Path('people')
* class PeopleService {
* @ DELETE
* @ Path(':id')
* removePerson(@ PathParam('id')id: string) {
* // ...
* }
* }
* ```
*
* Will create a service that listen for requests like:
*
* ```
* PUT http://mydomain/people/123
* ```
*/
export declare function DELETE(target: any, propertyKey: string, descriptor: PropertyDescriptor): void;
/**
* A decorator to tell the [[Server]] that a method
* should be called to process HTTP HEAD requests.
*
* For example:
*
* ```
* @ Path('people')
* class PeopleService {
* @ HEAD
* headPerson() {
* // ...
* }
* }
* ```
*
* Will create a service that listen for requests like:
*
* ```
* HEAD http://mydomain/people/123
* ```
*/
export declare function HEAD(target: any, propertyKey: string, descriptor: PropertyDescriptor): void;
/**
* A decorator to tell the [[Server]] that a method
* should be called to process HTTP OPTIONS requests.
*
* For example:
*
* ```
* @ Path('people')
* class PeopleService {
* @ OPTIONS
* optionsPerson() {
* // ...
* }
* }
* ```
*
* Will create a service that listen for requests like:
*
* ```
* OPTIONS http://mydomain/people/123
* ```
*/
export declare function OPTIONS(target: any, propertyKey: string, descriptor: PropertyDescriptor): void;
/**
* A decorator to tell the [[Server]] that a method
* should be called to process HTTP PATCH requests.
*
* For example:
*
* ```
* @ Path('people')
* class PeopleService {
* @ PATCH
* @ Path(':id')
* savePerson(person: Person) {
* // ...
* }
* }
* ```
*
* Will create a service that listen for requests like:
*
* ```
* PATCH http://mydomain/people/123
* ```
*/
export declare function PATCH(target: any, propertyKey: string, descriptor: PropertyDescriptor): void;
/**
* A decorator to inform options to pe passed to bodyParser.
* You can inform any property accepted by
* [[bodyParser]](https://www.npmjs.com/package/body-parser)
*/
export declare function BodyOptions(options: any): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void;
/**
* Creates a mapping between a fragment of the requested path and
* a method argument.
*
* For example:
*
* ```
* @ Path('people')
* class PeopleService {
* @ GET
* @ Path(':id')
* getPerson(@ PathParam('id') id: string) {
* // ...
* }
* }
* ```
*
* Will create a service that listen for requests like:
*
* ```
* GET http://mydomain/people/123
* ```
*
* And pass 123 as the id argument on getPerson method's call.
*/
export declare function PathParam(name: string): (...args: any[]) => any;
/**
* Creates a mapping between a file on a multipart request and a method
* argument.
*
* For example:
*
* ```
* @ Path('people')
* class PeopleService {
* @ POST
* @ Path('id')
* addAvatar(@ PathParam('id') id: string,
* @ FileParam('avatar') file: Express.Multer.File) {
* // ...
* }
* }
* ```
*
* Will create a service that listen for requests and bind the
* file with name 'avatar' on the requested form to the file
* argument on addAvatar method's call.
*/
export declare function FileParam(name: string): (...args: any[]) => any;
/**
* Creates a mapping between a list of files on a multipart request and a method
* argument.
*
* For example:
*
* ```
* @ Path('people')
* class PeopleService {
* @ POST
* @ Path('id')
* addAvatar(@ PathParam('id') id: string,
* @ FilesParam('avatar') Array<file>: Express.Multer.File) {
* // ...
* }
* }
* ```
*
* Will create a service that listen for requests and bind the
* files with name 'avatar' on the request form to the file
* argument on addAvatar method's call.
*/
export declare function FilesParam(name: string): (...args: any[]) => any;
/**
* Creates a mapping between a query parameter on request and a method
* argument.
*
* For example:
*
* ```
* @ Path('people')
* class PeopleService {
* @ GET
* getPeople(@ QueryParam('name') name: string) {
* // ...
* }
* }
* ```
*
* Will create a service that listen for requests like:
*
* ```
* GET http://mydomain/people?name=joe
* ```
*
* And pass 'joe' as the name argument on getPerson method's call.
*/
export declare function QueryParam(name: string): (...args: any[]) => any;
/**
* Creates a mapping between a header on request and a method
* argument.
*
* For example:
*
* ```
* @ Path('people')
* class PeopleService {
* @ GET
* getPeople(@ HeaderParam('header') header: string) {
* // ...
* }
* }
* ```
*
* Will create a service that listen for requests and bind the
* header called 'header' to the header argument on getPerson method's call.
*/
export declare function HeaderParam(name: string): (...args: any[]) => any;
/**
* Creates a mapping between a cookie on request and a method
* argument.
*
* For example:
*
* ```
* @ Path('people')
* class PeopleService {
* @ GET
* getPeople(@ CookieParam('cookie') cookie: string) {
* // ...
* }
* }
* ```
*
* Will create a service that listen for requests and bind the
* cookie called 'cookie' to the cookie argument on getPerson method's call.
*/
export declare function CookieParam(name: string): (...args: any[]) => any;
/**
* Creates a mapping between a form parameter on request and a method
* argument.
*
* For example:
*
* ```
* @ Path('people')
* class PeopleService {
* @ GET
* getPeople(@ FormParam('name') name: string) {
* // ...
* }
* }
* ```
*
* Will create a service that listen for requests and bind the
* request paramenter called 'name' to the name argument on getPerson
* method's call.
*/
export declare function FormParam(name: string): (...args: any[]) => any;
/**
* Creates a mapping between a parameter on request and a method
* argument.
*
* For example:
*
* ```
* @ Path('people')
* class PeopleService {
* @ GET
* getPeople(@ Param('name') name: string) {
* // ...
* }
* }
* ```
*
* Will create a service that listen for requests and bind the
* request paramenter called 'name' to the name argument on getPerson
* method's call. It will work to query parameters or form parameters
* received in the current request.
*/
export declare function Param(name: string): (...args: any[]) => any;