got README

项目的 README,来自 github.com/sindresorhus/got。合并为一个 markdown 文件:README.md。



Got




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



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>. It also exposes a .json(schema) function that validates the payload with a Standard Schema and infers the type from the schema.

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

got (sindresorhus/got)

正在搜索数据库…

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 流量。
有哪些类似的项目?ky, requests, guzzle, reqwest, httpx, hyper, pingora, mongoose
大小
4.5 MB
星标
15K
时长
12年
提交 · 90 天