got README

The project's README from github.com/sindresorhus/got. As one markdown file: README.md.



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

Comparison

got 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 aborting :heavy_check_mark: :heavy_check_mark: :heavy_check_mark: :heavy_check_mark: :heavy_check_mark:
RFC 7234 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.
: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 Sorhus Szymon Marczak
Sindre Sorhus Szymon 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

got (sindresorhus/got)

Searching Database…

15K ·GitHub
这是什么?Got 是一个对开发者友好、功能强大的 Node.js HTTP 请求库,提供 Promise API、流、分页、缓存、重试、钩子等功能。
这是框架,还是我需要导入的库?它是一个需要导入到 Node.js 项目中、用来发送 HTTP 请求的库,而不是独立的应用程序或框架。
我该如何把它添加到项目中?将它作为 npm 包安装,然后在 Node.js 代码中导入即可;它是一个单独的库,不是需要另外运行的服务。
使用它需要准备什么?需要 Node.js 22 或更高版本,并且你的项目必须使用 ESM,因为 Got 不再提供 CommonJS 构建版本。
安装时有哪些需要注意的坑吗?Got 现在只支持原生 ESM,不再提供 CommonJS 导出,因此使用 CommonJS 的项目必须转换为 ESM;较旧的 v11 分支已停止维护,也不会再提供向后移植的补丁。
为什么选择 Got,而不是 fetch、axios 或 superagent?Got 提供了许多其他方案开箱即用时通常缺少的功能,例如符合 RFC 7234 的缓存、高级重试和超时机制、Pagination API、Unix 套接字支持以及响应计时元数据。
Ky 是什么?什么时候应该改用它?Ky 是同一作者开发的姊妹项目,基于 Fetch API 构建。它体积更小,也可以在浏览器中运行;如果你不是特别需要 Got 仅限 Node.js 的功能,推荐使用它。
有针对特定服务的官方扩展吗?有的,比如用于 GitHub/GitLab API 的 gh-got 和 gl-got、用于 GraphQL 的 gotql、用于网页抓取的 got-scraping,以及用于防范 SSRF 攻击的 got-ssrf 等配套包。
Got 在生产环境中经过了多少考验?它被超过 10,000 个包和 500 万个代码仓库使用,Segment、Antora 和 Renovate 等公司也依赖它处理后端 HTTP 流量。
What are similar projects?ky, requests, request, guzzle, reqwest, httpx, hyper, captcha-api
Size
4.4 MB
Stars
15K
Age
12y
Commits · 90 Days