HttpTransportBuilder

HttpTransportBuilder

new HttpTransportBuilder(transport)

Source:

Configures HttpTransport client

Parameters:
Name Type Description
transport Transport

Transport instance.

Methods

createClient()

Source:

Instantiates a HttpTransport

Example
const client = httpTransport.createClient();
Returns:

a HttpTransport instance

retries(retries)

Source:

Set the default number of retries

Example
const httpTransport = require('@bbc/http-transport');

const builder = httpTransport.createBuilder();
builder.retries(5);
Parameters:
Name Type Description
retries integer

number of retry attempts

Returns:

a HttpTransportBuilder instance

retryDelay(delay)

Source:

default time delay between retries

Example
const httpTransport = require('@bbc/http-transport');

const builder = httpTransport.createBuilder();
builder.retryDelay(1000);
Parameters:
Name Type Description
delay integer

delay time in ms

Returns:

a HttpTransportBuilder instance

use(fn)

Source:

Registers a global plugin, which is used for all requests

Example
const toError = require('@bbc/http-transport-errors');
const httpTransport = require('@bbc/http-transport');

const client = httpTransport.createClient();
client.useGlobal(toError(404));
Parameters:
Name Type Description
fn function

a global plugin

Returns:

a HttpTransportBuilder instance

userAgent(agent)

Source:

Sets a default user agent

Example
const httpTransport = require('@bbc/http-transport');

const builder = httpTransport.createBuilder();
builder.userAgent('some-user-agent');
Parameters:
Name Type Description
agent string

user agent

Returns:

a HttpTransportBuilder instance