Class: Plug

Plug

A class for building URIs and performing HTTP requests.

Constructor

new Plug()

Source:

Members

headers

Get a Headers instance as defined by the fetch API.
Source:

url

Get a string representation of the URL used for HTTP requests.
Source:

Methods

at(…segments) → {Plug}

Get a new Plug, based on the current one, with the specified path segments added.
Parameters:
Name Type Attributes Description
segments String <repeatable>
The segments to be added to the new Plug instance.
Source:
Returns:
The Plug with the segments included.
Type
Plug

delete() → {Promise}

Perform an HTTP DELETE request.
Source:
Returns:
A Promise that, when resolved, yields the {Response} object as defined by the fetch API.
Type
Promise

get(methodopt) → {Promise}

Perform an HTTP GET Request.
Parameters:
Name Type Attributes Default Description
method String <optional>
GET The HTTP method to set as part of the GET logic.
Source:
Returns:
A Promise that, when resolved, yields the {Response} object as defined by the fetch API.
Type
Promise
Perform an HTTP HEAD request.
Source:
Returns:
A Promise that, when resolved, yields the {Response} object as defined by the fetch API.
Type
Promise

options() → {Promise}

Perform an HTTP OPTIONS request.
Source:
Returns:
A Promise that, when resolved, yields the {Response} object as defined by the fetch API.
Type
Promise

post(body, mime, methodopt) → {Promise}

Perform an HTTP POST request.
Parameters:
Name Type Attributes Default Description
body String The body of the POST.
mime String The mime type of the request, set in the `Content-Type` header.
method String <optional>
POST The HTTP method to use with the POST logic.
Source:
Returns:
A Promise that, when resolved, yields the {Response} object as defined by the fetch API.
Type
Promise

put(body, mime) → {Promise}

Perform an HTTP PUT request.
Parameters:
Name Type Description
body String The body of the PUT.
mime String The mime type of the request, set in the `Content-Type` header.
Source:
Returns:
A Promise that, when resolved, yields the {Response} object as defined by the fetch API.
Type
Promise

withFollowRedirects() → {Plug}

Get a new Plug, based on the current one, with follow redirects enabled
Source:
Returns:
A new Plug instance with follow redirects enabled
Type
Plug

withHeader(key, value) → {Plug}

Get a new Plug, based on the current one, with the specified header added.
Parameters:
Name Type Description
key String The name of the header to add.
value String The value of the header.
Source:
Returns:
A new Plug instance with the header included.
Type
Plug

withHeaders(values) → {Plug}

Get a new Plug, based on the current one, with the specified headers added.
Parameters:
Name Type Description
values Object A key-value list of the headers to include.
Source:
Returns:
A new Plug instance with the headers included.
Type
Plug

withoutFollowRedirects() → {Plug}

Get a new Plug, based on the current one, with follow redirects disabled
Source:
Returns:
A new Plug instance with follow redirects disabled
Type
Plug

withoutHeader(key) → {Plug}

Get a new Plug, based on the current one, with the specified header removed.
Parameters:
Name Type Description
key String The name of the header in the current Plug to remove.
Source:
Returns:
A new Plug instance with the header excluded.
Type
Plug

withoutParam(key) → {Plug}

Get a new Plug, based on the current one, with the specified query parameter removed.
Parameters:
Name Type Description
key String The key name of the query parameter in the current Plug to remove.
Source:
Returns:
A new Plug instance with the query parameter excluded.
Type
Plug

withParam(key, value) → {Plug}

Get a new Plug, based on the current one, with the specified query parameter added.
Parameters:
Name Type Description
key String The key name of the query parameter.
value String | Number | Boolean A value that will be serialized to a string and set as the query parameter value.
Source:
Returns:
A new Plug instance with the query parameter included.
Type
Plug

withParams(values) → {Plug}

Get a new Plug, based on the current one, with the specified query parameters added.
Parameters:
Name Type Description
values Object A key-value list of the query parameters to include.
Source:
Returns:
A new Plug instance with the query parameters included.
Type
Plug

Plug

new Plug(urlopt, optionsopt)

Parameters:
Name Type Attributes Default Description
url String <optional>
/ The initial URL to start the URL building from and to ultimately send HTTP requests to.
options Object <optional>
Options to direct the construction of the Plug.
Properties
Name Type Attributes Default Description
uriParts Object <optional>
An object representation of additional URI construction parameters.
Properties
Name Type Attributes Description
segments Array <optional>
An array of strings specifying path segments to be added to the URI.
query Object <optional>
A set of key-value pairs that specify query string entries to be added to the URI.
excludeQuery String <optional>
A query string key that will be removed from the URI if it was specified as part of the {@see uri} parameter or as an entry in {@see options.uriParts.query}.
headers Object <optional>
A set of key-value pairs that specify headers that will be set for every HTTP request sent by this instance.
timeout Number <optional>
null The time, in milliseconds, to wait before an HTTP timeout.
beforeRequest function <optional>
A function that is called before each HTTP request that allows per-request manipulation of the request headers and query parameters.
cookieManager Object <optional>
An object that implements a cookie management interface. This should provide implementations for the `getCookieString()` and `storeCookies()` functions.
followRedirects Boolean <optional>
Should HTTP redirects be auto-followed, or should HTTP redirect responses be returned to the caller (default: true)
fetchImpl function <optional>
whatwg/fetch implementation (default: window.fetch)
Source:

Members

headers

Get a Headers instance as defined by the fetch API.
Source:

url

Get a string representation of the URL used for HTTP requests.
Source:

Methods

at(…segments) → {Plug}

Get a new Plug, based on the current one, with the specified path segments added.
Parameters:
Name Type Attributes Description
segments String <repeatable>
The segments to be added to the new Plug instance.
Source:
Returns:
The Plug with the segments included.
Type
Plug

delete() → {Promise}

Perform an HTTP DELETE request.
Source:
Returns:
A Promise that, when resolved, yields the {Response} object as defined by the fetch API.
Type
Promise

get(methodopt) → {Promise}

Perform an HTTP GET Request.
Parameters:
Name Type Attributes Default Description
method String <optional>
GET The HTTP method to set as part of the GET logic.
Source:
Returns:
A Promise that, when resolved, yields the {Response} object as defined by the fetch API.
Type
Promise
Perform an HTTP HEAD request.
Source:
Returns:
A Promise that, when resolved, yields the {Response} object as defined by the fetch API.
Type
Promise

options() → {Promise}

Perform an HTTP OPTIONS request.
Source:
Returns:
A Promise that, when resolved, yields the {Response} object as defined by the fetch API.
Type
Promise

post(body, mime, methodopt) → {Promise}

Perform an HTTP POST request.
Parameters:
Name Type Attributes Default Description
body String The body of the POST.
mime String The mime type of the request, set in the `Content-Type` header.
method String <optional>
POST The HTTP method to use with the POST logic.
Source:
Returns:
A Promise that, when resolved, yields the {Response} object as defined by the fetch API.
Type
Promise

put(body, mime) → {Promise}

Perform an HTTP PUT request.
Parameters:
Name Type Description
body String The body of the PUT.
mime String The mime type of the request, set in the `Content-Type` header.
Source:
Returns:
A Promise that, when resolved, yields the {Response} object as defined by the fetch API.
Type
Promise

withFollowRedirects() → {Plug}

Get a new Plug, based on the current one, with follow redirects enabled
Source:
Returns:
A new Plug instance with follow redirects enabled
Type
Plug

withHeader(key, value) → {Plug}

Get a new Plug, based on the current one, with the specified header added.
Parameters:
Name Type Description
key String The name of the header to add.
value String The value of the header.
Source:
Returns:
A new Plug instance with the header included.
Type
Plug

withHeaders(values) → {Plug}

Get a new Plug, based on the current one, with the specified headers added.
Parameters:
Name Type Description
values Object A key-value list of the headers to include.
Source:
Returns:
A new Plug instance with the headers included.
Type
Plug

withoutFollowRedirects() → {Plug}

Get a new Plug, based on the current one, with follow redirects disabled
Source:
Returns:
A new Plug instance with follow redirects disabled
Type
Plug

withoutHeader(key) → {Plug}

Get a new Plug, based on the current one, with the specified header removed.
Parameters:
Name Type Description
key String The name of the header in the current Plug to remove.
Source:
Returns:
A new Plug instance with the header excluded.
Type
Plug

withoutParam(key) → {Plug}

Get a new Plug, based on the current one, with the specified query parameter removed.
Parameters:
Name Type Description
key String The key name of the query parameter in the current Plug to remove.
Source:
Returns:
A new Plug instance with the query parameter excluded.
Type
Plug

withParam(key, value) → {Plug}

Get a new Plug, based on the current one, with the specified query parameter added.
Parameters:
Name Type Description
key String The key name of the query parameter.
value String | Number | Boolean A value that will be serialized to a string and set as the query parameter value.
Source:
Returns:
A new Plug instance with the query parameter included.
Type
Plug

withParams(values) → {Plug}

Get a new Plug, based on the current one, with the specified query parameters added.
Parameters:
Name Type Description
values Object A key-value list of the query parameters to include.
Source:
Returns:
A new Plug instance with the query parameters included.
Type
Plug