Security News
Bun 1.2 Released with 90% Node.js Compatibility and Built-in S3 Object Support
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
@dnemoga/fetcher
Advanced tools
A minimalistic library built around the native Fetch API with zero dependencies.
A minimalistic library built around the native Fetch API with zero dependencies.
npm install @dnemoga/fetcher
import { Fetcher } from '@dnemoga/fetcher';
const fetcher = new Fetcher({ /* Fetcher Options */ });
These options apply to every request outcoming from the current instance.
mode
(default cors
)credentials
(default same-origin
)cache
(default default
)redirect
(default follow
)referrerPolicy
(default strict-origin-when-cross-origin
)fetcher.get('/resource', { /* Request Options */ })
.then(console.log, console.error);
| Note: Supported methods are get
, head
, post
, put
, patch
, and delete
.
data
Any body that you want to add to your request. Note that a request using the GET
or HEAD
method cannot have a body.
params
Any search parameters you want to add to your request, contained within an object literal with string values.
headers
Any headers you want to add to your request, contained within an object literal with string values. Note that some names are forbidden.
integrity
Contains the subresource integrity value of the request.
keepalive
The keepalive
option can be used to allow the request to outlive the page. Fetch with the keepalive
flag is a replacement for the Navigator.sendBeacon()
API.
signal
An AbortSignal
object instance; allows you to communicate with a fetch request and abort it if required via an AbortController
.
onRequest.use()
const customHeaders = async (request) => {
request.headers.set('X-Foo', 'Foo');
request.headers.set('X-Bar', 'Bar');
return request;
};
fetcher.onRequest.use(customHeaders);
onRequest.eject()
fetcher.onRequest.eject(customHeaders);
onResponse.use()
const errorHandler = async (response) => {
if (!response.ok) {
throw new Error(response.statusText);
}
return response;
};
fetcher.onResponse.use(errorHandler);
onResponse.eject()
fetcher.onResponse.eject(errorHandler);
fetcher.get('/resource', {
signal: AbortSignal.timeout(30000)
});
FAQs
A minimalistic library built around the native Fetch API with zero dependencies.
We found that @dnemoga/fetcher demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.