axios、got、isomorphic-fetch、node-fetch は、JavaScript 環境で HTTP 通信を行うための主要なライブラリです。axios はブラウザと Node.js の両方で動作する汎用クライアントとして広く使われています。got は Node.js 環境に特化し、高度な機能を提供します。node-fetch は Node.js で標準の fetch API を利用可能にします。isomorphic-fetch はかつてブラウザと Node.js を統一するポリフィルとして使われましたが、現在は非推奨となっています。
JavaScript で外部 API と通信する際、どの HTTP クライアントを選ぶかはプロジェクトの構成に大きく影響します。axios、got、node-fetch、isomorphic-fetch はそれぞれ異なる設計思想を持っており、適した場面が分かれています。ここでは、実務で直面する具体的な違いをコードを通じて比較します。
実行環境のサポート範囲は、ライブラリ選定の最初の基準になります。
axios はブラウザと Node.js の両方で動作します。
// axios: 両環境で動作
import axios from 'axios';
const res = await axios.get('/api/data');
got は Node.js 専用です。
// got: Node.js 専用
// ブラウザではエラーになります
import got from 'got';
const res = await got.get('https://api.example.com/data');
node-fetch は Node.js 環境での fetch 実装です。
fetch を使うため、このライブラリ自体は不要です。fetch を使いたい場合に利用します。// node-fetch: Node.js 用ポリフィル
import fetch from 'node-fetch';
const res = await fetch('https://api.example.com/data');
isomorphic-fetch はブラウザと Node.js を統一するポリフィルでした。
// isomorphic-fetch: 非推奨
// 現在は使用を避けるべきライブラリです
import 'isomorphic-fetch';
const res = await fetch('https://api.example.com/data');
データ取得と送信の基本構文を比較します。
axios はメソッドチェーンまたはオブジェクト設定を使います。
// axios: GET
await axios.get('/users', { params: { id: 1 } });
// axios: POST
await axios.post('/users', { name: 'Alice' });
got はメソッド名で操作します。
// got: GET
await got.get('https://api.example.com/users', { searchParams: { id: 1 } });
// got: POST
await got.post('https://api.example.com/users', { json: { name: 'Alice' } });
node-fetch は標準 fetch API に従います。
// node-fetch: GET
await fetch('https://api.example.com/users?id=1');
// node-fetch: POST
await fetch('https://api.example.com/users', {
method: 'POST',
body: JSON.stringify({ name: 'Alice' }),
headers: { 'Content-Type': 'application/json' }
});
isomorphic-fetch も標準 fetch API です。
node-fetch と全く同じです。fetch を呼び出します。// isomorphic-fetch: GET
await fetch('https://api.example.com/users?id=1');
// isomorphic-fetch: POST
await fetch('https://api.example.com/users', {
method: 'POST',
body: JSON.stringify({ name: 'Alice' }),
headers: { 'Content-Type': 'application/json' }
});
レスポンスの扱いとエラー発生時の挙動は、デバッグのしやすさに直結します。
axios は自動的に JSON をパースします。
res.data にパース済みのデータが入ります。// axios: レスポンス処理
try {
const res = await axios.get('/api/data');
console.log(res.data); // すでに JSON オブジェクト
} catch (error) {
console.error(error.response.status); // エラー詳細
}
got も自動的に JSON をパースします。
response.body にデータが入ります。HTTPError が投げられます。// got: レスポンス処理
try {
const res = await got.get('https://api.example.com/data');
console.log(res.body); // すでに JSON オブジェクト
} catch (error) {
console.error(error.response.statusCode); // エラー詳細
}
node-fetch は手動で JSON パースが必要です。
res.json() を明示的に呼び出します。// node-fetch: レスポンス処理
const res = await fetch('https://api.example.com/data');
if (!res.ok) {
throw new Error(`HTTP error! status: ${res.status}`);
}
const data = await res.json(); // 手動パース
console.log(data);
isomorphic-fetch も手動パースが必要です。
node-fetch と同一です。// isomorphic-fetch: レスポンス処理
const res = await fetch('https://api.example.com/data');
if (!res.ok) {
throw new Error(`HTTP error! status: ${res.status}`);
}
const data = await res.json(); // 手動パース
console.log(data);
リクエストの横断的な処理や中断機能の比較です。
axios はインターセプターを標準でサポートします。
// axios: インターセプター
axios.interceptors.request.use(config => {
config.headers.Authorization = 'Bearer token';
return config;
});
// axios: キャンセル
const controller = new AbortController();
axios.get('/api', { signal: controller.signal });
controller.abort();
got はフック機能を提供します。
// got: フック
const response = await got('https://api.example.com', {
hooks: {
beforeRequest: [
options => {
options.headers.authorization = 'Bearer token';
}
]
}
});
node-fetch は標準機能のみです。
// node-fetch: 自作ラッパー
async function fetchWithAuth(url) {
return fetch(url, {
headers: { Authorization: 'Bearer token' }
});
}
// キャンセルは AbortController で可能
const controller = new AbortController();
fetch('/api', { signal: controller.signal });
isomorphic-fetch は機能追加がありません。
// isomorphic-fetch: 機能なし
// 標準 fetch のまま使用するため、追加機能はありません
await fetch('/api');
ライブラリの維持状況は、長期的なプロジェクトにおいて重要です。
axios は活発にメンテナンスされています。
got も積極的に開発が続いています。
node-fetch は v3 で ESM 専用になりました。
isomorphic-fetch は非推奨です。
| 機能 | axios | got | node-fetch | isomorphic-fetch |
|---|---|---|---|---|
| 環境 | 🌐 ブラウザ + Node | 🖥️ Node のみ | 🖥️ Node のみ | 🌐 ブラウザ + Node |
| JSON パース | ✅ 自動 | ✅ 自動 | ❌ 手動 | ❌ 手動 |
| インターセプター | ✅ 標準搭載 | ✅ フック | ❌ 自作必要 | ❌ なし |
| ESM サポート | ✅ 対応 | ✅ 対応 | ✅ v3 のみ | ❌ 非推奨 |
| 推奨度 | ⭐⭐⭐⭐⭐ | ⭐⭐⭐⭐ | ⭐⭐⭐ | ⭐ |
axios は、ブラウザとサーバーをまたぐプロジェクトや、機能性を重視する場合の第一選択肢です。自動変換やインターセプターにより、開発効率が向上します。
got は、Node.js 限定のバックエンドタスクで真価を発揮します。ストリームや高度な制御が必要な場合に最適です。
node-fetch は、Node.js で fetch 構文を使いたい場合に有用ですが、Node.js 18 以降ではネイティブ機能で代用可能です。
isomorphic-fetch は、過去の資産を維持する場合を除き、新規採用は避けるべきです。
プロジェクトの要件と環境に合わせて、適切なツールを選ぶことが重要です — それが堅牢なアプリケーションへの近道です。
Node.js 環境限定で、ストリーム処理やページネーションなど高度な機能が必要なバックエンドスクリプトに適しています。モダンな構文と強力なエラー処理を求めている開発者に支持されています。
ブラウザと Node.js の両方で同じコードを動かしたい場合に最適です。インターセプターや自動 JSON 変換など、機能性が重視されるプロジェクトに向いています。大規模なアプリケーションでリクエストの統一管理が必要な際に選ばれます。
古い環境のポリフィルとして必要ない限り、新規プロジェクトでの使用は避けるべきです。代わりに node-fetch やネイティブ fetch を検討してください。メンテナンスが停止しているためリスクがあります。
Node.js で標準的な fetch API を使いたい場合に選択します。軽量で、ブラウザの fetch と同じ書き方ができます。Node.js 18 以降ではネイティブ fetch が使えるため、必要性は低下しています。
Sindre's open source work is supported by the community.
Special thanks to:
Human-friendly and powerful HTTP request library for Node.js
See how Got compares to other HTTP libraries
You probably want Ky instead, by the same people. It's smaller, works in the browser too, and is more stable since it's built on Fetch. Or fetch-extras for simple needs.
Support questions should be asked here.
npm install got
Warning: This package is native ESM and no longer provides a CommonJS export. If your project uses CommonJS, you will have to convert to ESM. Please don't open issues for questions regarding CommonJS / ESM.
Got v11 is no longer maintained and we will not accept any backport requests.
A quick start guide is available.
Got has a dedicated option for handling JSON payload.
Furthermore, the promise exposes a .json<T>() function that returns Promise<T>.
import got from 'got';
const {data} = await got.post('https://httpbin.org/anything', {
json: {
hello: 'world'
}
}).json();
console.log(data);
//=> {"hello": "world"}
For advanced JSON usage, check out the parseJson and stringifyJson options.
For more useful tips like this, visit the Tips page.
By default, Got will retry on failure. To disable this option, set options.retry.limit to 0.
got4aws - Got convenience wrapper to interact with AWS v4 signed APIsgh-got - Got convenience wrapper to interact with the GitHub APIgl-got - Got convenience wrapper to interact with the GitLab APIgotql - Got convenience wrapper to interact with GraphQL using JSON-parsed queries instead of stringsgot-fetch - Got with a fetch interfacegot-scraping - Got wrapper specifically designed for web scraping purposesgot-ssrf - Got wrapper to protect server-side requests against SSRF attacksgot | node-fetch | ky | axios | superagent | |
|---|---|---|---|---|---|
| HTTP/2 support | :heavy_check_mark:¹ | :x: | :heavy_check_mark: | :x: | :heavy_check_mark:** |
| Browser support | :x: | :heavy_check_mark:* | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
| Promise API | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
| Stream API | :heavy_check_mark: | Node.js only | :x: | :x: | :heavy_check_mark: |
| Pagination API | :heavy_check_mark: | :x: | :x: | :x: | :x: |
| Request cancelation | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
| RFC compliant caching | :heavy_check_mark: | :x: | :x: | :x: | :x: |
| Cookies (out-of-the-box) | :heavy_check_mark: | :x: | :x: | :x: | :x: |
| Follows redirects | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
| Retries on failure | :heavy_check_mark: | :x: | :heavy_check_mark: | :x: | :heavy_check_mark: |
| Progress events | :heavy_check_mark: | :x: | :heavy_check_mark: | Browser only | :heavy_check_mark: |
| Handles gzip/deflate | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
| Advanced timeouts | :heavy_check_mark: | :x: | :x: | :x: | :x: |
| Timings | :heavy_check_mark: | :x: | :x: | :x: | :x: |
| Errors with metadata | :heavy_check_mark: | :x: | :heavy_check_mark: | :heavy_check_mark: | :x: |
| JSON mode | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
| Custom defaults | :heavy_check_mark: | :x: | :heavy_check_mark: | :heavy_check_mark: | :x: |
| Composable | :heavy_check_mark: | :x: | :x: | :x: | :heavy_check_mark: |
| Hooks | :heavy_check_mark: | :x: | :heavy_check_mark: | :heavy_check_mark: | :x: |
| Issues open | |||||
| Issues closed | |||||
| Downloads | |||||
| Coverage | TBD | ||||
| Build | |||||
| Bugs | |||||
| Dependents | |||||
| Install size | |||||
| GitHub stars | |||||
| TypeScript support | |||||
| Last commit |
* It's almost API compatible with the browser fetch API.
** Need to switch the protocol manually. Doesn't accept PUSH streams and doesn't reuse HTTP/2 sessions.
¹ Requires Node.js 15.10.0 or above.
:sparkle: Almost-stable feature, but the API may change. Don't hesitate to try it out!
:grey_question: Feature in early stage of development. Very experimental.
Click here to see the install size of the Got dependencies.
![]() | ![]() |
|---|---|
| Sindre Sorhus | Szymon Marczak |
|
|
|
|
|
|
|
|
|
|
Segment is a happy user of Got! Got powers the main backend API that our app talks to. It's used by our in-house RPC client that we use to communicate with all microservices.
Antora, a static site generator for creating documentation sites, uses Got to download the UI bundle. In Antora, the UI bundle (aka theme) is maintained as a separate project. That project exports the UI as a zip file we call the UI bundle. The main site generator downloads that UI from a URL using Got and streams it to vinyl-zip to extract the files. Those files go on to be used to create the HTML pages and supporting assets.
GetVoIP is happily using Got in production. One of the unique capabilities of Got is the ability to handle Unix sockets which enables us to build a full control interfaces for our docker stack.
We're using Got inside of Exoframe to handle all the communication between CLI and server. Exoframe is a self-hosted tool that allows simple one-command deployments using Docker.
Karaoke Mugen uses Got to fetch content updates from its online server.
Renovate uses Got, gh-got and gl-got to send millions of queries per day to GitHub, GitLab, npmjs, PyPi, Packagist, Docker Hub, Terraform, CircleCI, and more.
Resistbot uses Got to communicate from the API frontend where all correspondence ingresses to the officials lookup database in back.
Natural Cycles is using Got to communicate with all kinds of 3rd-party REST APIs (over 9000!).
Microlink is a cloud browser as an API service that uses Got widely as the main HTTP client, serving ~22M requests a month, every time a network call needs to be performed.
We’re using Got at Radity. Thanks for such an amazing work!