From 51632d3f26c47a2f247b62fd275a92b3dc615db9 Mon Sep 17 00:00:00 2001 From: joaopedrodcf Date: Fri, 26 Dec 2025 18:16:29 +0000 Subject: [PATCH 1/2] Add node-fetch and cross-fetch --- docs/modules/README.md | 2 ++ docs/modules/cross-fetch.md | 58 +++++++++++++++++++++++++++++++++++++ docs/modules/node-fetch.md | 58 +++++++++++++++++++++++++++++++++++++ manifests/preferred.json | 12 ++++++++ 4 files changed, 130 insertions(+) create mode 100644 docs/modules/cross-fetch.md create mode 100644 docs/modules/node-fetch.md diff --git a/docs/modules/README.md b/docs/modules/README.md index f4114b0..d347b1f 100644 --- a/docs/modules/README.md +++ b/docs/modules/README.md @@ -23,6 +23,7 @@ ESLint plugin. - [`chalk`](./chalk.md) - [`core-util-is`](./core-util-is.md) - [`cpx`](./cpx.md) +- [`cross-fetch`](.cross-fetch.md) - [`crypto-js`](./crypto-js.md) - [`deep-equal`](./deep-equal.md) - [`depcheck`](./depcheck.md) @@ -60,6 +61,7 @@ ESLint plugin. - [`mkdirp`](./mkdirp.md) - [`moment.js`](./moment.md) - [`npm-run-all`](./npm-run-all.md) +- [`node-fetch`](.node-fetch.md) - [`object-hash`](./object-hash.md) - [`ora`](./ora.md) - [`path-exists`](./path-exists.md) diff --git a/docs/modules/cross-fetch.md b/docs/modules/cross-fetch.md new file mode 100644 index 0000000..4642210 --- /dev/null +++ b/docs/modules/cross-fetch.md @@ -0,0 +1,58 @@ +--- +description: cross-fetch was created at a time node didn't support fetch and it was useful to have the same API in browser and server,etc. It has still millions of downloads even if fetch since 18 ( experimental ) and 21 ( stable ) supports fetch API +--- + +# Replacements for `cross-fetch` + +## Native `fetch` API + +The native [`fetch`](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) API is available in Node.js (since v18.x) and all modern browsers. + +Example: + +```ts +// GET +const res = await fetch('https://api.example.com/data'); +const data = await res.json(); + +// POST +await fetch('https://api.example.com/data', { + method: 'POST', + headers: {'Content-Type': 'application/json'}, + body: JSON.stringify({key: 'value'}) +}); +``` + +## `ky` + +[`ky`](https://github.com/sindresorhus/ky) is a lightweight HTTP client based on the Fetch API with timeout support, hooks (interceptors) and other helpers. + +Example: + +```ts +import ky from 'ky'; + +const api = ky.create({ + prefixUrl: 'https://api.example.com', + timeout: 5000 // ms +}); + +const data = await api.get('users').json(); +``` + +## `ofetch` + +[`ofetch`](https://github.com/unjs/ofetch) s a fetch wrapper with automatic JSON parsing, request/response interceptors, and retries. + +Example: + +```ts +import {ofetch} from 'ofetch'; + +const api = ofetch.create({ + baseURL: 'https://api.example.com' +}); + +const data = await api('/user', {query: {id: 123}}); +const created = await api('/items', {method: 'POST', body: {name: 'A'}}); +``` diff --git a/docs/modules/node-fetch.md b/docs/modules/node-fetch.md new file mode 100644 index 0000000..f350d6a --- /dev/null +++ b/docs/modules/node-fetch.md @@ -0,0 +1,58 @@ +--- +description: node-fetch was a package created for fetch to run in node (similar to cross-fetch but cross-fetch is to work equal in browser and server), it has still millions of downloads even if fetch since 18 (experimental) and 21 (stable) supports fetch API +--- + +# Replacements for `node-fetch` + +## Native `fetch` API + +The native [`fetch`](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) API is available in Node.js (since v18.x) and all modern browsers. + +Example: + +```ts +// GET +const res = await fetch('https://api.example.com/data'); +const data = await res.json(); + +// POST +await fetch('https://api.example.com/data', { + method: 'POST', + headers: {'Content-Type': 'application/json'}, + body: JSON.stringify({key: 'value'}) +}); +``` + +## `ky` + +[`ky`](https://github.com/sindresorhus/ky) is a lightweight HTTP client based on the Fetch API with timeout support, hooks (interceptors) and other helpers. + +Example: + +```ts +import ky from 'ky'; + +const api = ky.create({ + prefixUrl: 'https://api.example.com', + timeout: 5000 // ms +}); + +const data = await api.get('users').json(); +``` + +## `ofetch` + +[`ofetch`](https://github.com/unjs/ofetch) s a fetch wrapper with automatic JSON parsing, request/response interceptors, and retries. + +Example: + +```ts +import {ofetch} from 'ofetch'; + +const api = ofetch.create({ + baseURL: 'https://api.example.com' +}); + +const data = await api('/user', {query: {id: 123}}); +const created = await api('/items', {method: 'POST', body: {name: 'A'}}); +``` diff --git a/manifests/preferred.json b/manifests/preferred.json index eaa7abc..204d481 100644 --- a/manifests/preferred.json +++ b/manifests/preferred.json @@ -72,6 +72,12 @@ "docPath": "cpx", "category": "preferred" }, + { + "type": "documented", + "moduleName": "cross-fetch", + "docPath": "cross-fetch", + "category": "preferred" + }, { "type": "documented", "moduleName": "crypto-js", @@ -2238,6 +2244,12 @@ "docPath": "npm-run-all", "category": "preferred" }, + { + "type": "documented", + "moduleName": "node-fetch", + "docPath": "node-fetch", + "category": "preferred" + }, { "type": "documented", "moduleName": "object-hash", From c9ec89d0ece673f9ce507272e85f123daf434f8e Mon Sep 17 00:00:00 2001 From: joaopedrodcf Date: Tue, 30 Dec 2025 22:35:16 +0000 Subject: [PATCH 2/2] Change to a single fetch file --- docs/modules/README.md | 6 +-- docs/modules/axios.md | 58 ----------------------- docs/modules/{cross-fetch.md => fetch.md} | 16 +++---- docs/modules/node-fetch.md | 58 ----------------------- manifests/preferred.json | 12 ++--- 5 files changed, 17 insertions(+), 133 deletions(-) delete mode 100644 docs/modules/axios.md rename docs/modules/{cross-fetch.md => fetch.md} (53%) delete mode 100644 docs/modules/node-fetch.md diff --git a/docs/modules/README.md b/docs/modules/README.md index d347b1f..00f9f37 100644 --- a/docs/modules/README.md +++ b/docs/modules/README.md @@ -13,7 +13,7 @@ ESLint plugin. ## List of modules - [`@jsdevtools/ezspawn`](./ez-spawn.md) -- [`axios`](./axios.md) +- [`axios`](./fetch.md) - [`bluebird`](./bluebird-q.md) - [`body-parser`](./body-parser.md) - [`buf-compare`](./buf-compare.md) @@ -23,7 +23,7 @@ ESLint plugin. - [`chalk`](./chalk.md) - [`core-util-is`](./core-util-is.md) - [`cpx`](./cpx.md) -- [`cross-fetch`](.cross-fetch.md) +- [`cross-fetch`](.fetch.md) - [`crypto-js`](./crypto-js.md) - [`deep-equal`](./deep-equal.md) - [`depcheck`](./depcheck.md) @@ -61,7 +61,7 @@ ESLint plugin. - [`mkdirp`](./mkdirp.md) - [`moment.js`](./moment.md) - [`npm-run-all`](./npm-run-all.md) -- [`node-fetch`](.node-fetch.md) +- [`node-fetch`](.fetch.md) - [`object-hash`](./object-hash.md) - [`ora`](./ora.md) - [`path-exists`](./path-exists.md) diff --git a/docs/modules/axios.md b/docs/modules/axios.md deleted file mode 100644 index 6b4499c..0000000 --- a/docs/modules/axios.md +++ /dev/null @@ -1,58 +0,0 @@ ---- -description: Modern alternatives to the axios package for making HTTP requests in browsers and Node.js ---- - -# Replacements for `axios` - -## Native `fetch` API - -The native [`fetch`](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) API is available in Node.js (since v18.x) and all modern browsers. For most HTTP requests, it can replace `axios` without extra dependencies. - -Example: - -```ts -// GET -const res = await fetch('https://api.example.com/data') -const data = await res.json() - -// POST -await fetch('https://api.example.com/data', { - method: 'POST', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ key: 'value' }) -}) -``` - -## `ky` - -[`ky`](https://github.com/sindresorhus/ky) is a lightweight HTTP client based on the Fetch API with timeout support, hooks (interceptors) and other helpers. - -Example: - -```ts -import ky from 'ky' - -const api = ky.create({ - prefixUrl: 'https://api.example.com', - timeout: 5000, // ms -}) - -const data = await api.get('users').json() -``` - -## `ofetch` - -[`ofetch`](https://github.com/unjs/ofetch) s a fetch wrapper with automatic JSON parsing, request/response interceptors, and retries. - -Example: - -```ts -import { ofetch } from 'ofetch' - -const api = ofetch.create({ - baseURL: 'https://api.example.com', -}) - -const data = await api('/user', { query: { id: 123 } }) -const created = await api('/items', { method: 'POST', body: { name: 'A' } }) -``` diff --git a/docs/modules/cross-fetch.md b/docs/modules/fetch.md similarity index 53% rename from docs/modules/cross-fetch.md rename to docs/modules/fetch.md index 4642210..21d1957 100644 --- a/docs/modules/cross-fetch.md +++ b/docs/modules/fetch.md @@ -1,12 +1,14 @@ --- -description: cross-fetch was created at a time node didn't support fetch and it was useful to have the same API in browser and server,etc. It has still millions of downloads even if fetch since 18 ( experimental ) and 21 ( stable ) supports fetch API +description: Shared alternatives and examples for fetch based HTTP clients used across related modules --- -# Replacements for `cross-fetch` +# Fetch-based HTTP clients (shared) + +This page contains the common, recommended alternatives and examples for fetch based HTTP clients used by `axios`, `node-fetch`, and `cross-fetch` replacement docs. ## Native `fetch` API -The native [`fetch`](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) API is available in Node.js (since v18.x) and all modern browsers. +The native [`fetch`](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) API is available in Node.js (since v18.x) and all modern browsers. For many use cases it replaces `axios`/`node-fetch`/`cross-fetch` without adding dependencies. Example: @@ -25,7 +27,7 @@ await fetch('https://api.example.com/data', { ## `ky` -[`ky`](https://github.com/sindresorhus/ky) is a lightweight HTTP client based on the Fetch API with timeout support, hooks (interceptors) and other helpers. +[`ky`](https://github.com/sindresorhus/ky) is a lightweight HTTP client built on top of the Fetch API. It adds convenience features like timeouts, hooks (interceptors), and a simpler API surface. Example: @@ -42,16 +44,14 @@ const data = await api.get('users').json(); ## `ofetch` -[`ofetch`](https://github.com/unjs/ofetch) s a fetch wrapper with automatic JSON parsing, request/response interceptors, and retries. +[`ofetch`](https://github.com/unjs/ofetch) is a small fetch wrapper with automatic JSON parsing, request/response interceptors, and retry support. Example: ```ts import {ofetch} from 'ofetch'; -const api = ofetch.create({ - baseURL: 'https://api.example.com' -}); +const api = ofetch.create({baseURL: 'https://api.example.com'}); const data = await api('/user', {query: {id: 123}}); const created = await api('/items', {method: 'POST', body: {name: 'A'}}); diff --git a/docs/modules/node-fetch.md b/docs/modules/node-fetch.md deleted file mode 100644 index f350d6a..0000000 --- a/docs/modules/node-fetch.md +++ /dev/null @@ -1,58 +0,0 @@ ---- -description: node-fetch was a package created for fetch to run in node (similar to cross-fetch but cross-fetch is to work equal in browser and server), it has still millions of downloads even if fetch since 18 (experimental) and 21 (stable) supports fetch API ---- - -# Replacements for `node-fetch` - -## Native `fetch` API - -The native [`fetch`](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) API is available in Node.js (since v18.x) and all modern browsers. - -Example: - -```ts -// GET -const res = await fetch('https://api.example.com/data'); -const data = await res.json(); - -// POST -await fetch('https://api.example.com/data', { - method: 'POST', - headers: {'Content-Type': 'application/json'}, - body: JSON.stringify({key: 'value'}) -}); -``` - -## `ky` - -[`ky`](https://github.com/sindresorhus/ky) is a lightweight HTTP client based on the Fetch API with timeout support, hooks (interceptors) and other helpers. - -Example: - -```ts -import ky from 'ky'; - -const api = ky.create({ - prefixUrl: 'https://api.example.com', - timeout: 5000 // ms -}); - -const data = await api.get('users').json(); -``` - -## `ofetch` - -[`ofetch`](https://github.com/unjs/ofetch) s a fetch wrapper with automatic JSON parsing, request/response interceptors, and retries. - -Example: - -```ts -import {ofetch} from 'ofetch'; - -const api = ofetch.create({ - baseURL: 'https://api.example.com' -}); - -const data = await api('/user', {query: {id: 123}}); -const created = await api('/items', {method: 'POST', body: {name: 'A'}}); -``` diff --git a/manifests/preferred.json b/manifests/preferred.json index 204d481..613f1af 100644 --- a/manifests/preferred.json +++ b/manifests/preferred.json @@ -9,7 +9,7 @@ { "type": "documented", "moduleName": "axios", - "docPath": "axios", + "docPath": "fetch", "category": "preferred" }, { @@ -75,7 +75,7 @@ { "type": "documented", "moduleName": "cross-fetch", - "docPath": "cross-fetch", + "docPath": "fetch", "category": "preferred" }, { @@ -2240,14 +2240,14 @@ }, { "type": "documented", - "moduleName": "npm-run-all", - "docPath": "npm-run-all", + "moduleName": "node-fetch", + "docPath": "fetch", "category": "preferred" }, { "type": "documented", - "moduleName": "node-fetch", - "docPath": "node-fetch", + "moduleName": "npm-run-all", + "docPath": "npm-run-all", "category": "preferred" }, {