Bivrost fetch adapter
Adapter for browser's native fetch function.
yarn add bivrost-fetch-adapter
Usage
With Bivrost:
;;; const api = ; static api = loadAll: ; { return this; }
Direct calls:
; const api = ; const options = method: 'GET' query: groupId: 10 headers: 'Content-Type': 'application/json' ; // /users?groupId=10 ; const options = method: 'POST' body: name: 'kek' headers: 'Content-Type': 'application/json' ; ;
Configuration
; const api = ;
Available options:
- headers - associated Headers object
- referrer - referrer of the request
- mode - cors, no-cors, same-origin
- credentials - should cookies go with the request? omit, same-origin
- redirect - follow, error, manual
- integrity - subresource integrity value
- cache - cache mode (default, reload, no-cache)
Interceptors
; const api = ;
-
Request object documentation - https://developer.mozilla.org/en-US/docs/Web/API/Request
-
Response object documentation - https://developer.mozilla.org/en-US/docs/Web/API/Response
NOTE: If there is a network error or another reason why the HTTP request couldn't be fulfilled, the fetch() promise will be rejected with a reference to that error.
Interceptor example:
; const api = ;
Fetch polyfill
Github whatwg-fetch - https://github.com/github/fetch
Bivrost allows to organize a simple interface to asyncronous APIs.