got vs axios vs isomorphic-fetch vs node-fetch
現代 Web 開発における HTTP クライアントの選定
gotaxiosisomorphic-fetchnode-fetch類似パッケージ:

現代 Web 開発における HTTP クライアントの選定

axiosgotisomorphic-fetchnode-fetch は、JavaScript 環境で HTTP 通信を行うための主要なライブラリです。axios はブラウザと Node.js の両方で動作する汎用クライアントとして広く使われています。got は Node.js 環境に特化し、高度な機能を提供します。node-fetch は Node.js で標準の fetch API を利用可能にします。isomorphic-fetch はかつてブラウザと Node.js を統一するポリフィルとして使われましたが、現在は非推奨となっています。

npmのダウンロードトレンド

3 年

GitHub Starsランキング

統計詳細

パッケージ
ダウンロード数
Stars
サイズ
Issues
公開日時
ライセンス
got31,278,18414,876304 kB12ヶ月前MIT
axios0108,5892.42 MB3477日前MIT
isomorphic-fetch06,927-575年前MIT
node-fetch08,858107 kB2333年前MIT

HTTP クライアントの比較:axios vs got vs fetch 系

JavaScript で外部 API と通信する際、どの HTTP クライアントを選ぶかはプロジェクトの構成に大きく影響します。axiosgotnode-fetchisomorphic-fetch はそれぞれ異なる設計思想を持っており、適した場面が分かれています。ここでは、実務で直面する具体的な違いをコードを通じて比較します。

🌍 実行環境:ブラウザと Node.js

実行環境のサポート範囲は、ライブラリ選定の最初の基準になります。

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 を使うため、このライブラリ自体は不要です。
  • Node.js 18 以前で 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');

📥 リクエスト送信:GET と POST

データ取得と送信の基本構文を比較します。

axios はメソッドチェーンまたはオブジェクト設定を使います。

  • URL とオプションを分離して記述できます。
  • デフォルトで JSON シリアライズを行います。
// axios: GET
await axios.get('/users', { params: { id: 1 } });

// axios: POST
await axios.post('/users', { name: 'Alice' });

got はメソッド名で操作します。

  • クエリパラメータはオブジェクトで渡します。
  • Node.js の URL モジュールとの相性が良いです。
// 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 に従います。

  • クエリパラメータは URL に直接埋め込むか、URL オブジェクトを使います。
  • ボディのシリアライズは手動で行う必要があります。
// 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' }
});

📤 レスポンス処理:JSON とエラー

レスポンスの扱いとエラー発生時の挙動は、デバッグのしやすさに直結します。

axios は自動的に JSON をパースします。

  • res.data にパース済みのデータが入ります。
  • 4xx、5xx エラーは例外としてスローされます。
// 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() を明示的に呼び出します。
  • 4xx、5xx でもエラーにならず、ok フラグで判定します。
// 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 はインターセプターを標準でサポートします。

  • トークン付与やロギングを一箇所で管理できます。
  • AbortController を使ったキャンセルも可能です。
// 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 はフック機能を提供します。

  • Node.js のイベントエミッターに近い感覚で使えます。
  • ストリーム処理との親和性が高いです。
// 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.js の新機能に素早く対応しています。
  • ドキュメントが充実しており、信頼性が高いです。

node-fetch は v3 で ESM 専用になりました。

  • CommonJS プロジェクトでは v2 を使う必要があります。
  • Node.js 18 以降ではネイティブ fetch があるため、役割は縮小しています。

isomorphic-fetch は非推奨です。

  • 公式に非推奨のアナウンスがあります。
  • セキュリティリスクがあるため、移行を検討すべきです。

📊 比較サマリー

機能axiosgotnode-fetchisomorphic-fetch
環境🌐 ブラウザ + Node🖥️ Node のみ🖥️ Node のみ🌐 ブラウザ + Node
JSON パース✅ 自動✅ 自動❌ 手動❌ 手動
インターセプター✅ 標準搭載✅ フック❌ 自作必要❌ なし
ESM サポート✅ 対応✅ 対応✅ v3 のみ❌ 非推奨
推奨度⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐

💡 結論

axios は、ブラウザとサーバーをまたぐプロジェクトや、機能性を重視する場合の第一選択肢です。自動変換やインターセプターにより、開発効率が向上します。

got は、Node.js 限定のバックエンドタスクで真価を発揮します。ストリームや高度な制御が必要な場合に最適です。

node-fetch は、Node.js で fetch 構文を使いたい場合に有用ですが、Node.js 18 以降ではネイティブ機能で代用可能です。

isomorphic-fetch は、過去の資産を維持する場合を除き、新規採用は避けるべきです。

プロジェクトの要件と環境に合わせて、適切なツールを選ぶことが重要です — それが堅牢なアプリケーションへの近道です。

選び方: got vs axios vs isomorphic-fetch vs node-fetch

  • got:

    Node.js 環境限定で、ストリーム処理やページネーションなど高度な機能が必要なバックエンドスクリプトに適しています。モダンな構文と強力なエラー処理を求めている開発者に支持されています。

  • axios:

    ブラウザと Node.js の両方で同じコードを動かしたい場合に最適です。インターセプターや自動 JSON 変換など、機能性が重視されるプロジェクトに向いています。大規模なアプリケーションでリクエストの統一管理が必要な際に選ばれます。

  • isomorphic-fetch:

    古い環境のポリフィルとして必要ない限り、新規プロジェクトでの使用は避けるべきです。代わりに node-fetch やネイティブ fetch を検討してください。メンテナンスが停止しているためリスクがあります。

  • node-fetch:

    Node.js で標準的な fetch API を使いたい場合に選択します。軽量で、ブラウザの fetch と同じ書き方ができます。Node.js 18 以降ではネイティブ fetch が使えるため、必要性は低下しています。

got のREADME



Got




Sindre's open source work is supported by the community.
Special thanks to:



Fame Helsinki Fame Helsinki



Depot logo
Fast remote container builds and GitHub Actions runners.











Human-friendly and powerful HTTP request library for Node.js

Downloads Install size

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.

Install

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.

Take a peek

A quick start guide is available.

JSON mode

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.

Highlights

Documentation

By default, Got will retry on failure. To disable this option, set options.retry.limit to 0.

Main API

Timeouts and retries

Advanced creation

Cache, Proxy and UNIX sockets

Integration


Migration guides

Got plugins

  • got4aws - Got convenience wrapper to interact with AWS v4 signed APIs
  • gh-got - Got convenience wrapper to interact with the GitHub API
  • gl-got - Got convenience wrapper to interact with the GitLab API
  • gotql - Got convenience wrapper to interact with GraphQL using JSON-parsed queries instead of strings
  • got-fetch - Got with a fetch interface
  • got-scraping - Got wrapper specifically designed for web scraping purposes
  • got-ssrf - Got wrapper to protect server-side requests against SSRF attacks

Comparison

gotnode-fetchkyaxiossuperagent
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
CoverageTBD
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.

Maintainers

Sindre SorhusSzymon Marczak
Sindre SorhusSzymon Marczak

These amazing companies are using Got


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.

Vadim Demedes

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.

Dan Allen

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.

Daniel Kalen

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.

Tim Ermilov

Karaoke Mugen uses Got to fetch content updates from its online server.

Axel Terizaki

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.

Rhys Arkins

Resistbot uses Got to communicate from the API frontend where all correspondence ingresses to the officials lookup database in back.

Chris Erickson

Natural Cycles is using Got to communicate with all kinds of 3rd-party REST APIs (over 9000!).

Kirill Groshkov

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.

Kiko Beats

We’re using Got at Radity. Thanks for such an amazing work!

Mirzayev Farid