Class: DefaultResponseProxy

QuickNav

DefaultResponseProxy

Provides a fetch event listener which uses the default Fetch and Cache strategies.

Constructor

new DefaultResponseProxy(options)

Default Response Proxy
Parameters:
Name Type Argument Description
options {jsonProcessor: Object, fetchStrategy: function(), cacheStrategy: function()} <optional>
Options

Methods

(static) getResponseProxy(options)

Return an instance of the default response proxy
Parameters:
Name Type Argument Description
options {jsonProcessor: Object, fetchStrategy: function(), cacheStrategy: function()} <optional>
Options
  • options.jsonProcessor An object containing the JSON shredder, unshredder, and queryHandler for the responses.
  • options.jsonProcessor.shredder JSON shredder for the responses
  • options.jsonProcessor.unshredder JSON unshredder for the responses
  • options.queryHandler query parameter handler. Should be a function object which takes a Request and returns a Promise which resolves with a Response when the query parameters have been processed. If the Request was not handled then resolve to null. The queryHandler object also contains an optional function named normalizeQueryParameter that takes a request URL and returns the normalized query parameters as defined in NormalizedQuery
  • options.fetchStrategy Should be a function which takes a Request and returns a Promise which resolves to a Response If unspecified then uses the default.
  • options.cacheStrategy Should be a function which returns a Promise which resolves with a response when the cache expiration behavior has been processed. If unspecified then uses the default which uses the HTTP cache headers to determine cache expiry.
  • options.requestHandlerOverride An object containing request handler overrides.
  • options.requestHandlerOverride.handleGet Override the default GET request handler with the supplied function. The function should take a Request object as parameter and return a Promise which resolves to a Response object.
  • options.requestHandlerOverride.handlePost Override the default POST request handler with the supplied function. The function should take a Request object as parameter and return a Promise which resolves to a Response object.
  • options.requestHandlerOverride.handlePut Override the default PUT request handler with the supplied function. The function should take a Request object as parameter and return a Promise which resolves to a Response object.
  • options.requestHandlerOverride.handlePatch Override the default PATCH request handler with the supplied function. The function should take a Request object as parameter and return a Promise which resolves to a Response object.
  • options.requestHandlerOverride.handleDelete Override the default DELETE request handler with the supplied function. The function should take a Request object as parameter and return a Promise which resolves to a Response object.
  • options.requestHandlerOverride.handleHead Override the default HEAD request handler with the supplied function. The function should take a Request object as parameter and return a Promise which resolves to a Response object.
  • options.requestHandlerOverride.handleOptions Override the default OPTIONS request handler with the supplied function. The function should take a Request object as parameter and return a Promise which resolves to a Response object.

getFetchEventListener() → {Function}

Returns the Fetch Event listener
Returns:
Returns the fetch event listener
Type
function

handleDelete(request) → {Promise}

The default DELETE request handler. Processes the DELETE Request using the default logic. Can be overridden to provide custom processing logic.
Parameters:
Name Type Description
request Request Request object
Returns:
Returns a Promise which resolves to a Response object
Type
Promise

handleGet(request) → {Promise}

The default GET request handler. Processes the GET Request using the default logic. Can be overrided to provide custom processing logic.
Parameters:
Name Type Description
request Request Request object
Returns:
Returns a Promise which resolves to a Response object
Type
Promise

handleHead(request) → {Promise}

The default HEAD request handler. Processes the HEAD Request using the default logic. Can be overrided to provide custom processing logic.
Parameters:
Name Type Description
request Request Request object
Returns:
Returns a Promise which resolves to a Response object
Type
Promise

handleOptions(request) → {Promise}

The default OPTIONS request handler. The default implementation when offline will return a Response with '503 Service Unavailable' error code.
Parameters:
Name Type Description
request Request Request object
Returns:
Returns a Promise which resolves to a Response object
Type
Promise

handlePatch(request) → {Promise}

The default PATCH request handler. The default implementation when offline will return a Response with '503 Service Unavailable' error code.
Parameters:
Name Type Description
request Request Request object
Returns:
Returns a Promise which resolves to a Response object
Type
Promise

handlePost(request) → {Promise}

The default POST request handler. The default implementation when offline will return a Response with '503 Service Unavailable' error code.
Parameters:
Name Type Description
request Request Request object
Returns:
Returns a Promise which resolves to a Response object
Type
Promise

handlePut(request) → {Promise}

The default PUT request handler. Processes the PUT Request using the default logic. Can be overrided to provide custom processing logic.
Parameters:
Name Type Description
request Request Request object
Returns:
Returns a Promise which resolves to a Response object
Type
Promise

processRequest(request) → {Function}

Process the Request. Use this function if you want to chain request processing within a fetch event listener.
Parameters:
Name Type Description
request Request Request object
Returns:
Promise
Type
function