PlatformRequest
Usage
import { PlatformRequest } from "@tsed/platform-http";
See /packages/platform/platform-http/src/types/common/services/PlatformRequest.ts.
Overview
class PlatformRequest<Req extends {
[key: string]: any;
} = any> {
readonly $ctx: PlatformContext;
constructor($ctx: PlatformContext);
get response(): PlatformResponse;
get raw(): Req;
get secure(): boolean;
get host(): string;
get protocol(): string;
get url(): string;
get headers(): IncomingHttpHeaders;
get method(): string;
get body(): any;
get rawBody(): any;
get cookies(): {
[key: string]: any;
};
get params(): {
[key: string]: any;
};
get query(): {
[key: string]: any;
};
get session(): {
[key: string]: any;
};
get files(): any;
get route(): import("@tsed/platform-router").SinglePathType;
get request(): Req;
get req(): IncomingMessage;
get(name: string): any;
getHeader(name: string): any;
accepts(mime: string): string | false;
accepts(mime: string[]): string[] | false;
isAborted(): any;
getRequest<R = Req>(): R;
getReq(): IncomingMessage;
}
Description
Platform Request abstraction layer.
[key: string]
[key: string]: any;
}
} = any> {
readonly $ctx
readonly $ctx: PlatformContext;
get response
get response(): PlatformResponse;
The current PlatformResponse.
get raw
get raw(): Req;
get secure
get secure(): boolean;
get host
get host(): string;
get protocol
get protocol(): string;
get url
get url(): string;
Get the url of the request.
Is equivalent of express.response.originalUrl || express.response.url
.
get headers
get headers(): IncomingHttpHeaders;
get method
get method(): string;
get body
get body(): any;
Contains key-value pairs of data submitted in the request body. By default, it is undefined
, and is populated when you use body-parsing
middleware such as express.json()
or express.urlencoded()
.
get rawBody
get rawBody(): any;
get cookies
get cookies(): {
[key: string]: any;
};
When using cookie-parser
middleware, this property is an object that contains cookies sent by the request. If the request contains no cookies, it defaults to {}
.
get params
get params(): {
[key: string]: any;
};
This property is an object containing properties mapped to the named route parameters
. For example, if you have the route /user/:name
, then the name
property is available as req.params.name
. This object defaults to {}
.
get query
get query(): {
[key: string]: any;
};
This property is an object containing a property for each query string parameter in the route. When query parser is set to disabled, it is an empty object {}
, otherwise it is the result of the configured query parser.
get session
get session(): {
[key: string]: any;
};
This property is an object containing a property for each session attributes set by any code. It requires to install a middleware like express-session to work.
get files
get files(): any;
get route
get route(): import("@tsed/platform-router").SinglePathType;
get request
get request(): Req;
Return the original request framework instance
get req
get req(): IncomingMessage;
Return the original request node.js instance
get
get(name: string): any;
Returns the HTTP request header specified by field. The match is case-insensitive.
request.get('Content-Type') // => "text/plain"
getHeader
getHeader(name: string): any;
accepts
accepts(mime: string): string | false;
Checks if the specified content types are acceptable, based on the request’s Accept HTTP header field. The method returns the best match, or if none of the specified content types is acceptable, returns false (in which case, the application should respond with 406 "Not Acceptable").
The type value may be a single MIME type string (such as “application/json”), an extension name such as “json”, a comma-delimited list, or an array. For a list or array, the method returns the best match (if any).
accepts
accepts(mime: string[]): string[] | false;
isAborted
isAborted(): any;
getRequest
getRequest<R = Req>(): R;
Return the Framework response object (express, koa, etc...)
getReq
getReq(): IncomingMessage;
Return the Node.js response object