# RequestContext Class

Module
import { RequestContext } from "@tsed/common"
Source/packages/common/src/platform/domain/RequestContext.ts

# Overview

class RequestContext extends Map<any, any> {
    readonly id: string;
    readonly dateStart: Date;
    container: LocalsContainer<any>;
    endpoint: EndpointMetadata;
    data: any;
    logger: RequestLogger;
    injector: InjectorService;
    destroy(): Promise<void>;
    emit(eventName: string, ...args: any[]): Promise<void>;
}

# Members

readonly id: string

Request id generated by contextMiddleware.

TIP

By default Ts.ED generate uuid like that uuidv4().replace(/-/gi, "")). Dash are removed to simplify tracking logs in Kibana

TIP

Request id can by customized by changing the server configuration.

@ServerSettings({
  logger: {
    reqIdBuilder: createUniqId // give your own id generator function
  }
})
class Server {

}
1
2
3
4
5
6
7
8

:::


readonly dateStart: Date

Date when request have been handled by the server. RequestLogger use this date to log request duration.


container: LocalsContainer<any>

The request container used by the Ts.ED DI. It contain all services annotated with @Scope(ProviderScope.REQUEST)


The current EndpointMetadata resolved by Ts.ED during the request.


data: any

The data return by the previous endpoint if you use multiple handler on the same route. By default data is empty.


Logger attached to the context request.


injector: InjectorService

destroy(): Promise<void>

emit(eventName: string, ...args: any[]): Promise<void>