Prioritize
A light ES6 wrapper on fetch to facilitate prioritization of calls.
Prioritize
A light wrapper on fetch to facilitate prioritization of calls.
npm install prioritize
-
Prioritize
- .baseUrl
- .defaults
-
.fetch(url, [settings]) ⇒
Promise
-
.get(url, [settings]) ⇒
Promise
-
.patch(url, [settings]) ⇒
Promise
-
.put(url, [settings]) ⇒
Promise
-
.post(url, [settings]) ⇒
Promise
-
.delete(url, [settings]) ⇒
Promise
prioritize.baseUrl
A baseUrl to prepend to the url for each call to fetch.
Default: window.location.protocol + '//' + window.location.host
prioritize.defaults
Default settings for each call to fetch.
Default: { headers: { 'Content-Type': 'application/json' } }
prioritize.fetch(url, [settings]) ⇒ Promise
Prioritized call to fetch.
Returns: Promise
- Should be handled like a normal call to fetch.
Param | Type | Description |
---|---|---|
url | string |
URL to call. |
[settings] | object |
All settings available to fetch. - Adds any default settings from prioritize.defaults .- settings.body is passed through JSON.stringify() if appropriate. |
[settings.priority] | string |
If set to "low" then this call is added to a queue until all ongoing calls are complete. |
[settings.params] | object |
Search parameters to append to the url. example: { a: 1 } => ?a=1 . Objects and Arrays are passed through JSON.stringify() . |
prioritize.get(url, [settings]) ⇒ Promise
Shortcut to
prioritize.fetch
withmethod: 'GET'
.
Returns: Promise
- Should be handled like a normal call to fetch.
Param | Type | Description |
---|---|---|
url | string |
URL to call. |
[settings] | object |
Passed to prioritize.fetch with method: 'GET' . |
prioritize.patch(url, [settings]) ⇒ Promise
Shortcut to
prioritize.fetch
withmethod: 'PATCH'
.
Returns: Promise
- Should be handled like a normal call to fetch.
Param | Type | Description |
---|---|---|
url | string |
URL to call. |
[settings] | object |
Passed to prioritize.fetch with method: 'PATCH' . |
prioritize.put(url, [settings]) ⇒ Promise
Shortcut to
prioritize.fetch
withmethod: 'PUT'
.
Returns: Promise
- Should be handled like a normal call to fetch.
Param | Type | Description |
---|---|---|
url | string |
URL to call. |
[settings] | object |
Passed to prioritize.fetch with method: 'PUT' . |
prioritize.post(url, [settings]) ⇒ Promise
Shortcut to
prioritize.fetch
withmethod: 'POST'
.
Returns: Promise
- Should be handled like a normal call to fetch.
Param | Type | Description |
---|---|---|
url | string |
URL to call. |
[settings] | object |
Passed to prioritize.fetch with method: 'POST' . |
prioritize.delete(url, [settings]) ⇒ Promise
Shortcut to
prioritize.fetch
withmethod: 'DELETE'
.
Returns: Promise
- Should be handled like a normal call to fetch.
Param | Type | Description |
---|---|---|
url | string |
URL to call. |
[settings] | object |
Passed to prioritize.fetch with method: 'DELETE' . |