This code is forked from @sapphire/fetch
code, i forked because of they still uses node-fetch instead undici.
usage may same with @sapphire/fetch
- Written in TypeScript
- Exported const enum for the common return data types.
- Support ESM & CommonJS
npm install @kirishima/fetch undici
// Import the fetch function
import { fetch, FetchResultTypes } from '@kirishima/fetch';
interface JsonPlaceholderResponse {
userId: number;
id: number;
title: string;
completed: boolean;
}
// Fetch the data. No need to call `.json()` after making the request!
const data = await fetch<JsonPlaceholderResponse>('https://jsonplaceholder.typicode.com/todos/1', undefined, FetchResultTypes.JSON);
// Do something with the data
console.log(data.userId);