gofor
Each Gofor instance exposes a fetch method: a lean, isomorphic fetch decorator that deep reverse merges default options.
Options you pass through in for each request will take precedence, but will supplemented with the defaults.
Installation
npm i gofor
Usage
Gofor
class
Using the const Gofor = ;const myGofor = headers: 'X-Custom-Header': 'Custom-Value'; myGofor ;
"Out of the box" usability with instances
You can opt to import the gofor
property to get a working instance with the default environment Headers
:
const gofor = ; ; // This is the fetch
Each call to Gofor.gofor
generates a new instance:
const gofor1 = gofor;const gofor2 = gofor; gofor1 === gofor2 // false
Configuring an instance
const gofor = ;const defaultHeaders = ; defaultHeaders;defaultHeaders;defaultHeaders; gofor; // Use only defaults; // Add/Apply other options;
Headers
Setting Gofor
supports setting headers either as an object literal or as a Headers
instance
Default header keys will be run over if matched by passed in header keys. Other keys will be merged. This is made by design.
Example
// Configure using the "Headers" constructor gofor; // Or, using an object literal gofor; ;
Final headers will be:
'Content-Type': 'text/plain' 'X-Custom-Header': 'Custom-Value'
Delayed configuration
The function will be called once on first use, and its result will be memoised. useful for cases where you need to pull information from the document and don't want to create a race condition.
const gofor = ; gofor;
FAQ
How do I migrate from version 2 to version 3?
The two breaking changes in version 3 are:
- Deprecation of the server entry (
gofor/server
) in favor of a truly isomorphic solution. - Deprecation of the
dist
folder.