prioritize

A light ES6 wrapper on fetch to facilitate prioritization of calls.

Usage no npm install needed!

<script type="module">
  import prioritize from 'https://cdn.skypack.dev/prioritize';
</script>

README

Prioritize

A light ES6 wrapper on fetch to facilitate prioritization of calls.

npm build coverage deps size vulnerabilities license


Prioritize

A light wrapper on fetch to facilitate prioritization of calls.

npm install prioritize


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 with method: '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 with method: '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 with method: '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 with method: '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 with method: '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'.