Getting Started
In this guide, you’ll quickly learn how to get up and running with Fetchtastic. Let’s dive in and start making your network requests declarative and predictable!
Installation
Install Fetchtastic using the package manager of your preference:
- npm
- pnpm
- yarn
npm install fetchtastic
pnpm add fetchtastic
yarn add fetchtastic
Import
import { fetchtastic } from 'fetchtastic';
Compatibility
Fetchtastic is built on standard web APIs like fetch, Headers, URL, and URLSearchParams, ensuring it integrates smoothly into any JavaScript or TypeScript project. By extending the native fetch API, it adds predictability and type safety to network requests, making them easier to manage and debug.
So you can leverage familiar web standards for handling headers and URLs. It uses the Headers interface for managing request and response headers, and URL and URLSearchParams for constructing and manipulating URLs and query parameters. This adherence to web standards ensures compatibility and consistency across various JavaScript and TypeScript environments, whether you’re working in a browser, Node.js, or another runtime.
- Modern browsers
- Service Workers
- Deno
- Node.js >= v18
- Netlify Edge Functions
- Vercel Edge Functions
Deno
Npm specifier
import { fetchtastic } from 'npm:fetchtastic';
JSR
deno add @fveracoechea/fetchtastic
import { fetchtastic } from '@fveracoechea/fetchtastic';
Remote import
import { fetchtastic } from 'https://deno.land/x/fetchtastic/lib/mod.ts';
Polyfills for Node.js < v18
For older versions, the Node.js standard library does not provide a native implementation of fetch and other Browsers-only APIs so polyfilling is mandatory, you can do so by using these npm packages:
import fetch, { FormData } from 'node-fetch';
global.fetch = fetch;
global.FormData = FormData;