module:store/Rest

module:store/Rest

This class encapsulates functionality for communicating with the repository via Ajax calls. Authentication is done via cookies and accept headers are in general set to application/json behind the scenes.

Constructor

new (require("store/Rest"))()

Source:

Methods

(async) auth(credentials) → {Promise}

Source:
Parameters:
Name Type Description
credentials object

should contain attributes "user", "password", and "maxAge". MaxAge is the amount of seconds the authorization should be valid.

Returns:

A thenable object

Type
Promise

(async) create(uri, data) → {Promise.<String>}

Source:

Posts data to a factory resource with the intent to create a new resource. That is, it posts data and expects a Location header back with information on the created resource.

Parameters:
Name Type Description
uri string

factory resource, may include parameters.

data string | Object

the data that is to be posted as a string, if an object is provided it will be serialized as json.

Returns:
Type
Promise.<String>

del(uri, modDateopt) → {Promise}

Source:

Deletes a resource.

Parameters:
Name Type Attributes Description
uri String

of the resource that is to be deleted.

modDate Date <optional>

a date to use for the HTTP if-unmodified-since header.

Returns:

A thenable object

Type
Promise

disableJSONP()

Source:

Disable JSONP for all requests, e.g. when there is a need for performance and there is a need for relable caching which does not work with JSONP.

enableJSONP()

Source:

Enable JSONP for all get requests. JSONP will only be used if EntryStore.js is running in the browser and there are cross-site GET requests. Note that JSONP is enabled in this scenario by default.

(async) get(uri, format, nonJSONP) → {Promise}

Source:

Fetches data from the provided URI. If a cross-domain call is made and we are in a browser environment a jsonp call is made.

Parameters:
Name Type Default Description
uri string

URI to a resource to fetch.

format string | null null

the format to request as a mimetype.

nonJSONP boolean false

stop JSONP handling (default false)

Throws:

Error

Returns:

A thenable object

Type
Promise

post(uri, data, modDateopt, formatopt) → {Promise}

Source:

Posts data to the provided URI.

Parameters:
Name Type Attributes Description
uri String

an URI to post to.

data String | Object

the data to post. If an object the data is sent as form data.

modDate Date <optional>

a date to use for the HTTP if-unmodified-since header.

format string <optional>

indicates the content-type of the data, default is application/json, except if the data is an object in which case the default is multipart/form-data.

Returns:

A thenable object

Type
Promise

put(uri, data, modDateopt, formatopt) → {Promise}

Source:

Replaces a resource with a new representation.

Parameters:
Name Type Attributes Description
uri string

the address to put to.

data string | Object

the data to put. If an object the data is sent as form data.

modDate Date <optional>

a date to use for the HTTP if-unmodified-since header.

format string <optional>

indicates the content-type of the data, default is application/json, except if the data is an object in which case the default is multipart/form-data.

Returns:

A thenable object

Type
Promise

putFile(uri, data, format) → {Promise}

Source:

Post a file to a URI. In a browser environment a file is represented via an input tag which references the file to be uploaded via its value attribute. In node environments the file is represented as a stream constructed via fs.createReadStream('file.txt').

Under the hood the tag is moved into a form in an invisible iframe which then is submitted. If there is a response it is provided in a textarea which can be looked into since we are on the same domain.

Parameters:
Name Type Description
uri string

the URI to which we will put the file.

data data

input tag or stream that may for instance correspond to a file in a nodejs setting.

format string

the format to handle the response as, either text, xml, html or json (json is default).

Returns:

A thenable object

Type
Promise