跳转至

Got 文档

人性化和强大的 Node.js HTTP 请求库

Downloads Install size

了解 get 与其他 HTTP 库的比较


对于浏览器使用,我们推荐同样的人Ky


支持问题应该问这里.

安装

npm install got

Warning

这个包是原生的ESM,不再提供CommonJS导出。 如果你的项目使用CommonJS,你将不得不转换为ESM或使用dynamic import() 函数。 请不要打开关于CommonJS / ESM的问题。 我们只会将关键的安全问题移植到Got v11,而不是功能或错误修复。

看一眼

快速入门指南可用。

JSON mode

Got 有一个专门的选项来处理 JSON 有效负载 此外,promise 暴露了一个.json<T>()函数,该函数返回 Promise<T>

import got from "got";

const { data } = await got
  .post("https://httpbin.org/anything", {
    json: {
      hello: "world",
    },
  })
  .json();

console.log(data);
//=> {"hello": "world"}

对于高级 JSON 用法,请查看 parseJson stringifyJson 选项。

要了解更多有用的技巧,请访问tips页面。

Highlights

文档

默认情况下,Got 将在失败时重试。要禁用此选项,请将 options.retry.limit 设置为 0。

主要 API

超时并重试

先进的创造

缓存,代理和 UNIX socket

集成


迁移向导

Got 插件

  • 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

遗产

  • travis-got - Got 方便包装与特拉维斯 API 交互
  • graphql-got - Got 方便的包装与 GraphQL 交互

比较

got node-fetch ky axios superagent
HTTP/2 support ✔¹ ❌ ❌ ❌ ✔**
Browser support ❌ ✔* ✔ ✔ ✔
Promise API ✔ ✔ ✔ ✔ ✔
Stream API ✔ Node.js only ❌ ❌ ✔
Pagination API ✔ ❌ ❌ ❌ ❌
Request cancelation ✔ ✔ ✔ ✔ ✔
RFC compliant caching ✔ ❌ ❌ ❌ ❌
Cookies (out-of-box) ✔ ❌ ❌ ❌ ❌
Follows redirects ✔ ✔ ✔ ✔ ✔
Retries on failure ✔ ❌ ✔ ❌ ✔
Progress events ✔ ❌ ✔*** Browser only ✔
Handles gzip/deflate ✔ ✔ ✔ ✔ ✔
Advanced timeouts ✔ ❌ ❌ ❌ ❌
Timings ✔ ❌ ❌ ❌ ❌
Errors with metadata ✔ ❌ ✔ ✔ ❌
JSON mode ✔ ✔ ✔ ✔ ✔
Custom defaults ✔ ❌ ✔ ✔ ❌
Composable ✔ ❌ ❌ ❌ ✔
Hooks ✔ ❌ ✔ ✔ ❌
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.\ *** Currently, only DownloadProgress event is supported, UploadProgress event is not supported.\ ¹ Requires Node.js 15.10.0 or above.\ ❇ Almost-stable feature, but the API may change. Don't hesitate to try it out!\ ❔ Feature in early stage of development. Very experimental.

Click here to see the install size of the Got dependencies.

维护人员

Sindre Sorhus Szymon Marczak
Sindre Sorhus Szymon Marczak

这些了不起的公司正在使用 Got


段是一个快乐的用户!Got 为应用程序对话的主后端 API 提供了动力。它被我们的内部 RPC 客户端使用,我们用它来与所有微服务通信。

Vadim Demedes

Antora 是一个用于创建文档站点的静态站点生成器,它使用 Got 来下载 UI 包。 在 Antora 中,UI 包(又名主题)是作为一个单独的项目维护的。 该项目将 UI 导出为 zip 文件,我们称之为 UI 包。 主站点生成器使用 Got 从 URL 下载该 UI,并将其传输到 vinyl-zip 以提取文件。 这些文件将继续用于创建 HTML 页面和支持资产。

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 has been a crucial component of Apify's scraping for years. We use it to extract data from billions of web pages every month, and we really appreciate the powerful API and extensibility, which allowed us to build our own specialized HTTP client on top of Got. The support has always been stellar too.

Ondra Urban

为企业

Available as part of the Tidelift Subscription.

The maintainers of got and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. Learn more.