Constructor
new Store(String, Object)
Parameters:
Name | Type | Description |
---|---|---|
String |
collection - RESTful resource name | |
Object |
request - Override request parameters in `fetch()`. |
Methods
as(String)
Define the format of the request, expressed as a file extension.
Parameters:
Name | Type | Description |
---|---|---|
String |
format - File extension of the resource |
at(string)
Define the base URL of the request
Parameters:
Name | Type | Description |
---|---|---|
string |
url - Base URL to request from |
byID(String)
Manipulate the `path` of this request to use the ID given in the
argument.
Parameters:
Name | Type | Description |
---|---|---|
String |
id - ID of the resource. |
catch(Function)
Attach a `callback` to the error state of the `Promise` returned by
`fetch()`. This function will be called whenever the promise is
rejected.
Parameters:
Name | Type | Description |
---|---|---|
Function |
callback |
done()
Convenience method for invoking the `Promise` returned by
`fetch()`, but not needing to actually pass a callback into it.
Returns:
Object the return value of the `Promise`.
sort(String, String)
Manipulate the query params to use the given `by` and `direction`
values in the `sort` param.
Parameters:
Name | Type | Description |
---|---|---|
String |
by - Param to sort by | |
String |
direction - Direction to sort, e.g. "up", "down", |
then(Function)
Invoke the `Promise` returned by `fetch()` and pass the given
callback into it.
Parameters:
Name | Type | Description |
---|---|---|
Function |
callback |
Returns:
Object the return value of the `Promise`.
where(Object)
Pass the given `params` as query parameters to the request.
Parameters:
Name | Type | Description |
---|---|---|
Object |
params - Query parameters |
with(Object)
Send a payload along with the HTTP request. When the `body` passed
in is a JS object, it will be converted into JSON, but if it is a
String we will just use the raw value as the body.
Parameters:
Name | Type | Description |
---|---|---|
Object |
body - Payload to be sent. |