Context

Context

The Context encapsulates the state/context of a given resource or request, including extensions available, the http mechanism for dereferencing URLs, etc.

Constructor

new Context()

Create a new context with the given http abstraction and set of extensions

Source:

Methods

acceptHeader() → {string}

Generate an HTTP Accept header from the extension media types, preferring the context content type over others, e.g application/vnd.siren+json;application/json;q=0.5.

Source:
Returns:

The generated Accept header value

Type
string

baseline() → {Context}

Create a copy of the context with any base URL removed.

Source:
Returns:

the new context with base URL context removed.

Type
Context

forResource(resource) → {Context}

Create a copy of the context with a new resource context

Parameters:
Name Type Description
resource Object

The context resource object.

Properties
Name Type Description
url String

The new context URL.

headers Object

The headers of the resource context.

Source:
Returns:

The new context with the given resource.

Type
Context

resolveUrl(url)

Given a possibly relative URL, resolve it using the context's base URL, if it exists.

Parameters:
Name Type Description
url String

The (possibly relative) URL to resolve.

Source:
Returns:

String The resolved URL. This may still be relative is no base URL is set in the given context.

withDefaults(optionsopt) → {Object}

Merge the default options with the provided ones to produce the final options for a follow operation.

Parameters:
Name Type Attributes Description
options Object <optional>

The request specific options.

Source:
Returns:

The merged options.

Type
Object

withExtensions(extensions) → {Context}

Create a new context with the provided extensions overriding the existing ones.

Parameters:
Name Type Description
extensions Array

The new set of extensions to use for the context

Source:
Returns:

A new context w/ the provided extensions

Type
Context