Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs/modules/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -23,6 +23,7 @@ ESLint plugin.
- [`chalk`](./chalk.md)
- [`core-util-is`](./core-util-is.md)
- [`cpx`](./cpx.md)
- [`cross-fetch`](.fetch.md)
- [`crypto-js`](./crypto-js.md)
- [`deep-equal`](./deep-equal.md)
- [`depcheck`](./depcheck.md)
Expand Down Expand Up @@ -60,6 +61,7 @@ ESLint plugin.
- [`mkdirp`](./mkdirp.md)
- [`moment.js`](./moment.md)
- [`npm-run-all`](./npm-run-all.md)
- [`node-fetch`](.fetch.md)
- [`object-hash`](./object-hash.md)
- [`ora`](./ora.md)
- [`path-exists`](./path-exists.md)
Expand Down
58 changes: 0 additions & 58 deletions docs/modules/axios.md

This file was deleted.

58 changes: 58 additions & 0 deletions docs/modules/fetch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---
description: Shared alternatives and examples for fetch based HTTP clients used across related modules
---

# 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. For many use cases it replaces `axios`/`node-fetch`/`cross-fetch` without adding 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 built on top of the Fetch API. It adds convenience features like timeouts, hooks (interceptors), and a simpler API surface.

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) 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 data = await api('/user', {query: {id: 123}});
const created = await api('/items', {method: 'POST', body: {name: 'A'}});
```
14 changes: 13 additions & 1 deletion manifests/preferred.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
{
"type": "documented",
"moduleName": "axios",
"docPath": "axios",
"docPath": "fetch",
"category": "preferred"
},
{
Expand Down Expand Up @@ -72,6 +72,12 @@
"docPath": "cpx",
"category": "preferred"
},
{
"type": "documented",
"moduleName": "cross-fetch",
"docPath": "fetch",
"category": "preferred"
},
{
"type": "documented",
"moduleName": "crypto-js",
Expand Down Expand Up @@ -2232,6 +2238,12 @@
"docPath": "moment",
"category": "preferred"
},
{
"type": "documented",
"moduleName": "node-fetch",
"docPath": "fetch",
"category": "preferred"
},
{
"type": "documented",
"moduleName": "npm-run-all",
Expand Down