Skip to main content
Version: v1

RequestParser Class

The Request Parser takes an IRequest provides parsing and sub request creation

Signature​

export declare class RequestParser implements IRequest

Implements: IRequest

Constructors​

ConstructorDescription
(constructor)(request)Constructs a new instance of the RequestParser class

Static Methods​

MethodReturn TypeDescription
create(request)RequestParser
getPathParts(url)readonly string[]Splits the path of the url and decodes each path part

Properties​

PropertyTypeDescription
headersIRequestHeader | undefined
pathPartsreadonly string[]Returns the decoded path parts of the request's url
querystring
urlstring

Methods​

MethodReturn TypeDescription
createSubRequest(startingPathIndex)IRequest

Creates a sub request starting at a specific path part of this request's url The sub request url always has a leading slash, and always include query params if original url has any e.g. original url is /a/b/?queryParams, createSubRequest(0) is /a/b/?queryParams createSubRequest(1) is /b/?queryParams createSubRequest(2) is /?queryParams createSubRequest(n) where n is bigger than parts length, e.g. 2, or n is less than 0 will throw an exception

note: query params are not counted towards path parts.

isLeaf(elements)booleanReturns true if it's a terminating path, i.e. no more elements after elements entries and empty query.

Constructor Details​

(constructor)​

Constructs a new instance of the RequestParser class

Signature​

protected constructor(request: Readonly<IRequest>);

Parameters​

ParameterTypeDescription
requestReadonly<IRequest>

Property Details​

headers​

Signature​

get headers(): IRequestHeader | undefined;

Type: IRequestHeader | undefined

pathParts​

Returns the decoded path parts of the request's url

Signature​

get pathParts(): readonly string[];

Type: readonly string[]

query​

Signature​

readonly query: string;

Type: string

url​

Signature​

get url(): string;

Type: string

Method Details​

create​

Signature​

static create(request: Readonly<IRequest>): RequestParser;

Parameters​

ParameterTypeDescription
requestReadonly<IRequest>

Returns​

Return type: RequestParser

createSubRequest​

Creates a sub request starting at a specific path part of this request's url The sub request url always has a leading slash, and always include query params if original url has any e.g. original url is /a/b/?queryParams, createSubRequest(0) is /a/b/?queryParams createSubRequest(1) is /b/?queryParams createSubRequest(2) is /?queryParams createSubRequest(n) where n is bigger than parts length, e.g. 2, or n is less than 0 will throw an exception

note: query params are not counted towards path parts.

Signature​

createSubRequest(startingPathIndex: number): IRequest;

Parameters​

ParameterTypeDescription
startingPathIndexnumberThe index of the first path part of the sub request

Returns​

Return type: IRequest

getPathParts​

Splits the path of the url and decodes each path part

Signature​

static getPathParts(url: string): readonly string[];

Parameters​

ParameterTypeDescription
urlstringthe url to get path parts of

Returns​

Return type: readonly string[]

isLeaf​

Returns true if it's a terminating path, i.e. no more elements after elements entries and empty query.

Signature​

isLeaf(elements: number): boolean;

Parameters​

ParameterTypeDescription
elementsnumbernumber of elements in path

Returns​

Return type: boolean