# EndpointMetadata Class

Module
import { EndpointMetadata } from "@tsed/common"
Source/packages/common/src/mvc/models/EndpointMetadata.ts

# Overview

class EndpointMetadata extends Storable implements EndpointConstructorOptions {
    provide: Type<any>;
    beforeMiddlewares: any[];
    middlewares: any[];
    afterMiddlewares: any[];
    /**
     * Route strategy.
     */
    pathsMethods: IPathMethod[];
    readonly responses: Map<number, IResponseOptions>;
    statusCode: number;
    constructor(options: EndpointConstructorOptions);
    get type(): Type<any>;
    set type(type: Type<any>);
    get targetName(): string;
    get params(): ParamMetadata[];
    get response(): IResponseOptions;
    get view(): EndpointViewOptions;
    set view(view: EndpointViewOptions);
    get location(): string;
    set location(url: string);
    get redirect(): EndpointRedirectOptions;
    set redirect(options: EndpointRedirectOptions);
    /**
     * @deprecated Will be removed in v6
     */
    get contentType(): string;
    /**
     * @deprecated Will be removed in v6
     */
    set contentType(url: string);
    /**
     * Get all endpoints from a given class and his parents.
     * @param {Type<any>} target
     * @returns {EndpointMetadata[]}
     */
    static getEndpoints(target: Type<any>): EndpointMetadata[];
    /**
     * Get an endpoint.
     * @param target
     * @param propertyKey
     * @param descriptor
     */
    static get(target: Type<any>, propertyKey: string | symbol, descriptor?: PropertyDescriptor): EndpointMetadata;
    /**
     * Gets a value indicating whether the target object or its prototype chain has already method registered.
     * @param target
     * @param method
     * @deprecated
     */
    static has(target: Type<any>, method: string | symbol): boolean;
    /**
     * Append mvc in the pool (before).
     * @param target
     * @param targetKey
     * @param args
     * @deprecated
     */
    static useBefore(target: Type<any>, targetKey: string | symbol, args: any[]): typeof EndpointMetadata;
    /**
     * Add middleware and configuration for the endpoint.
     * @param target
     * @param targetKey
     * @param args
     * @returns {Endpoint}
     * @deprecated
     */
    static use(target: Type<any>, targetKey: string | symbol, args: any[]): typeof EndpointMetadata;
    /**
     * Append mvc in the pool (after).
     * @param target
     * @param targetKey
     * @param args
     * @deprecated
     */
    static useAfter(target: Type<any>, targetKey: string | symbol, args: any[]): typeof EndpointMetadata;
    /**
     * Find the a value at the controller level. Let this value be extended or overridden by the endpoint itself.
     *
     * @param key
     * @returns {any}
     */
    get<T = any>(key: any): T;
    /**
     * Change the type and the collection type from the status code.
     * @param {string | number} code
     * @deprecated Use endpoint.responses.get(code)
     */
    statusResponse(code: string | number): IResponseOptions;
    /**
     *
     * @param args
     * @returns {EndpointMetadata}
     */
    before(args: Function[]): this;
    /**
     *
     * @param args
     * @returns {EndpointMetadata}
     */
    after(args: Function[]): this;
    /**
     * Store all arguments collected via Annotation.
     * @param args
     */
    use(args: Function[]): this;
    /**
     * Store all arguments collected via Annotation.
     * @param args
     * @deprecated
     */
    merge(args: any[]): this;
    clone(): EndpointMetadata;
}

# Description

EndpointMetadata contains metadata about a controller and his method. Each annotation (@Get, @Body...) attached to a method are stored in a endpoint. EndpointMetadata convert this metadata to an array which contain arguments to call an Express method.

Example :

@Controller("/my-path") provide MyClass {

   @Get("/")
   @Authenticated()
   public myMethod(){}

}

# Members

provide: Type<any>;

beforeMiddlewares: any[];

middlewares: any[];

afterMiddlewares: any[];

pathsMethods: IPathMethod[];

Route strategy.


readonly responses: Map<number, IResponseOptions>;

statusCode: number;

get type(): Type<any>;

set type(type: Type<any>);

get targetName(): string;

get params(): ParamMetadata[];

get response(): IResponseOptions;

get view(): EndpointViewOptions;

set view(view: EndpointViewOptions);

get location(): string;

set location(url: string);

get redirect(): EndpointRedirectOptions;

set redirect(options: EndpointRedirectOptions);

get contentType(): string;

set contentType(url: string);

static getEndpoints(target: Type<any>): EndpointMetadata[];

Get all endpoints from a given class and his parents.


static get(target: Type<any>, propertyKey: string | symbol, descriptor?: PropertyDescriptor): EndpointMetadata;

Get an endpoint.


static has(target: Type<any>, method: string | symbol): boolean;

Gets a value indicating whether the target object or its prototype chain has already method registered.


static useBefore(target: Type<any>, targetKey: string | symbol, args: any[]): typeof EndpointMetadata;

Append mvc in the pool (before).


static use(target: Type<any>, targetKey: string | symbol, args: any[]): typeof EndpointMetadata;

Add middleware and configuration for the endpoint.


static useAfter(target: Type<any>, targetKey: string | symbol, args: any[]): typeof EndpointMetadata;

Append mvc in the pool (after).


get<T = any>(key: any): T;

Find the a value at the controller level. Let this value be extended or overridden by the endpoint itself.


statusResponse(code: string | number): IResponseOptions;

Change the type and the collection type from the status code.


before(args: Function[]): this;

after(args: Function[]): this;

use(args: Function[]): this;

Store all arguments collected via Annotation.


merge(args: any[]): this;

Store all arguments collected via Annotation.