Home Manual Reference Source
public class | source

Request

Constructor Summary

Public Constructor
public

constructor(name: string, params: object)

Member Summary

Public Members
public

The endpoint schematic.

public

Which custom headers to be added to the request.

public

The request name (used to reference the endpoint).

public

The request parameters, used for the path, body etc...

Method Summary

Public Methods
public

addHeader(name: string, value: string): Request

Adds a header to the Request.

public

Adds multiple headers to the Request.

public

addParam(name: string, value: string): Request

A parameter to add to the Request.

public

addParams(params: Object<string, *>): Request

Adds multiple parameters to the Request.

public

build(): {method: string, path: string, query: string, body: string, headers: Object<string, string>}

Returns an object containing all the final metadata about the request.

public

Gets the request body (serialised).

public

Gets the headers to be used when making the request.

public

Gets the request method (verb).

public

Gets the full pathname of the endpoint, plus any additional parameters or trailing slashes as defined in the endpoint schematic.

public

Gets the query string of the url.

Public Constructors

public constructor(name: string, params: object) source

Params:

NameTypeAttributeDescription
name string

The endpoint name (found in endpoints.json)

params object
  • optional

The parameters to pass to the endpoint

Public Members

public endpoint: Endpoint source

The endpoint schematic. This schematic defines how the parameters should be used, what HTTP method, and what the pathname is to the endpoint - as well as other various details.

public headers: Object<string, string> source

Which custom headers to be added to the request.

public name: string source

The request name (used to reference the endpoint).

public params: Object<string, *> source

The request parameters, used for the path, body etc...

Public Methods

public addHeader(name: string, value: string): Request source

Adds a header to the Request.

Params:

NameTypeAttributeDescription
name string

The header name

value string

The header value

Return:

Request

public addHeaders(headers: Object<string, string>): Request source

Adds multiple headers to the Request.

Params:

NameTypeAttributeDescription
headers Object<string, string>

A map of the headers to add to the request

Return:

Request

public addParam(name: string, value: string): Request source

A parameter to add to the Request.

Params:

NameTypeAttributeDescription
name string

The header name

value string

The header value

Return:

Request

public addParams(params: Object<string, *>): Request source

Adds multiple parameters to the Request.

Params:

NameTypeAttributeDescription
params Object<string, *>

A map of parameters to add to the request

Return:

Request

public build(): {method: string, path: string, query: string, body: string, headers: Object<string, string>} source

Returns an object containing all the final metadata about the request.

This return value is also the value used to pass through to the IRequestAdapter. It's intended to make it easy to write request adapters without having to implement the serialisation of requests per adapter.

Return:

{method: string, path: string, query: string, body: string, headers: Object<string, string>}

See:

public getBody(): string source

Gets the request body (serialised).

This method is in charge of serialising the request body in the correct format, as defined in the endpoint's version value. Version 1 of the API uses x-www-form-urlencoded, where as version 2 uses application/json.

Return:

string

public getHeaders(): Object<string, string> source

Gets the headers to be used when making the request.

This method automatically adds headers like Content-Type and X-PageProof-JavaScript-SDK.

Return:

Object<string, string>

public getMethod(): string source

Gets the request method (verb).

Return:

string

public getPath(): string source

Gets the full pathname of the endpoint, plus any additional parameters or trailing slashes as defined in the endpoint schematic.

Return:

string

public getQuery(): string source

Gets the query string of the url. This string is appended after the path.

This method is seperated from the Request.getPath method, as the authorization HMAC does not include the query parameter as part of it's calculation.

If there is no query string, this method always returns an empty string.

Return:

string