# Class PlatformRequest

Class platform
Module
import { PlatformRequest } from "@tsed/common"
Source/packages/common/src/platform/services/PlatformRequest.ts

# Overview

class PlatformRequest<T extends {
    [key: string]: any;
} = any> {
    raw: T;
    constructor(raw: T);
    get secure(): boolean;
    get host(): string;
    get protocol(): string;
get <span class="token function">url</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token keyword">string</span><span class="token punctuation">;</span>
get <span class="token function">headers</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span> IncomingHttpHeaders<span class="token punctuation">;</span>
get <span class="token function">method</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token keyword">string</span><span class="token punctuation">;</span>

get <span class="token function">body</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token keyword">any</span><span class="token punctuation">;</span>
get <span class="token function">rawBody</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token keyword">any</span><span class="token punctuation">;</span>

get <span class="token function">cookies</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token punctuation">{</span>
    <span class="token punctuation">[</span>key<span class="token punctuation">:</span> <span class="token keyword">string</span><span class="token punctuation">]</span><span class="token punctuation">:</span> <span class="token keyword">any</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span><span class="token punctuation">;</span>

get <span class="token function">params</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token punctuation">{</span>
    <span class="token punctuation">[</span>key<span class="token punctuation">:</span> <span class="token keyword">string</span><span class="token punctuation">]</span><span class="token punctuation">:</span> <span class="token keyword">any</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span><span class="token punctuation">;</span>

get <span class="token function">query</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token punctuation">{</span>
    <span class="token punctuation">[</span>key<span class="token punctuation">:</span> <span class="token keyword">string</span><span class="token punctuation">]</span><span class="token punctuation">:</span> <span class="token keyword">any</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span><span class="token punctuation">;</span>

get <span class="token function">session</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token punctuation">{</span>
    <span class="token punctuation">[</span>key<span class="token punctuation">:</span> <span class="token keyword">string</span><span class="token punctuation">]</span><span class="token punctuation">:</span> <span class="token keyword">any</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span><span class="token punctuation">;</span>

<span class="token keyword">static</span> <span class="token function">create</span><span class="token punctuation">(</span>injector<span class="token punctuation">:</span> <a href="/api/di/services/InjectorService.html"><span class="token">InjectorService</span></a><span class="token punctuation">,</span> req<span class="token punctuation">:</span> TsED.<a href="/api/common/mvc/decorators/params/Request.html"><span class="token">Request</span></a><span class="token punctuation">)</span><span class="token punctuation">:</span> PlatformRequest&lt;<span class="token keyword">any</span>&gt;<span class="token punctuation">;</span>

<span class="token function">get</span><span class="token punctuation">(</span>name<span class="token punctuation">:</span> <span class="token keyword">string</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token keyword">any</span><span class="token punctuation">;</span>

<span class="token function">accepts</span><span class="token punctuation">(</span>mime<span class="token punctuation">:</span> <span class="token keyword">string</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token keyword">string</span> | false<span class="token punctuation">;</span>
<span class="token function">accepts</span><span class="token punctuation">(</span>mime<span class="token punctuation">:</span> <span class="token keyword">string</span><span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token keyword">string</span><span class="token punctuation">[</span><span class="token punctuation">]</span> | false<span class="token punctuation">;</span>
<span class="token function">isAborted</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token keyword">any</span><span class="token punctuation">;</span>
<span class="token function">destroy</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token keyword">void</span><span class="token punctuation">;</span>

getRequest&lt;<a href="/api/common/mvc/decorators/params/Req.html"><span class="token">Req</span></a><span class="token punctuation"> = </span>T&gt;<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <a href="/api/common/mvc/decorators/params/Req.html"><span class="token">Req</span></a><span class="token punctuation">;</span>

<span class="token function">getReq</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span> IncomingMessage<span class="token punctuation">;</span>

}

# Description

Platform Request abstraction layer.

# Members

[key: string]: any;

} = any> {

raw: T;

get secure(): boolean;

get host(): string;

get protocol(): string;

get url(): string;

Get the url of the request.

Is equivalent of express.response.originalUrl || express.response.url.


get headers(): IncomingHttpHeaders;

get method(): string;

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(): any;

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(): {
     [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(): {
     [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(): {
     [key: string]: any;
 };

This property is an object containing a property for each session attributes set by any code. It require to install a middleware like express-session to work.


static create(injector: InjectorService, req: TsED.Request): PlatformRequest<any>;

Create a new instance of PlatformRequest


get(name: string): any;

Returns the HTTP request header specified by field. The match is case-insensitive.

request.get('Content-Type') // => "text/plain"
1

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(mime: string[]): string[] | false;

isAborted(): any;

destroy(): void;

getRequest<Req = T>(): Req;

Return the Framework response object (express, koa, etc...)


getReq(): IncomingMessage;

Return the Node.js response object

Other topics