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

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

Static Methods

Method Return Type Description
create(request) RequestParser
getPathParts(url) readonly string[] Splits the path of the url and decodes each path part

Properties

Property Type Description
headers IRequestHeader | undefined
pathParts readonly string[] Returns the decoded path parts of the request's url
query string
url string

Methods

Method Return Type Description
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) boolean Returns 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

Parameter Type Description
request Readonly<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

Parameter Type Description
request Readonly<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

Parameter Type Description
startingPathIndex number The 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

Parameter Type Description
url string the 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

Parameter Type Description
elements number number of elements in path

Returns

Return type: boolean