Got

为 Node.js 开发的人性化且功能强大的 HTTP 请求库。「Human-friendly and powerful HTTP request library for Node.js」

Github星跟踪图

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

Build Status: Linux
Coverage Status
Downloads
Install size

Moving from Request? (Note that Request is unmaintained)

See how Got compares to other HTTP libraries

For browser usage, we recommend Ky by the same people.

Highlights

Install

$ npm install got

Usage

const got = require('got');

(async () => {
	try {
		const response = await got('https://sindresorhus.com');
		console.log(response.body);
		//=> '<!doctype html> ...'
	} catch (error) {
		console.log(error.response.body);
		//=> 'Internal server error ...'
	}
})();
Streams
const stream = require('stream');
const {promisify} = require('util');
const fs = require('fs');
const got = require('got');

const pipeline = promisify(stream.pipeline);

(async () => {
    await pipeline(
        got.stream('https://sindresorhus.com'),
        fs.createWriteStream('index.html')
    );

    // For POST, PUT, and PATCH methods `got.stream` returns a `stream.Writable`
    await pipeline(
        fs.createReadStream('index.html'),
        got.stream.post('https://sindresorhus.com')
    );
})();

Tip: Using from.pipe(to) doesn't forward errors. If you use it, switch to Stream.pipeline(from, ..., to, callback) instead (available from Node v10).

API

It's a GET request by default, but can be changed by using different methods or via options.method.

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

got(url?, options?)

Returns a Promise for a response object or a stream if options.isStream is set to true.

url

Type: `string

主要指标

概览
名称与所有者sindresorhus/got
主编程语言TypeScript
编程语言TypeScript (语言数: 1)
平台Linux, Mac, Windows
许可证MIT License
所有者活动
创建于2014-03-27 22:40:49
推送于2025-03-31 14:47:32
最后一次提交
发布数178
最新版本名称v14.4.7 (发布于 2025-03-31 20:04:25)
第一版名称v0.1.0 (发布于 2014-03-27 23:43:16)
用户参与
星数14.6k
关注者数111
派生数1k
提交数1.5k
已启用问题?
问题数1473
打开的问题数127
拉请求数537
打开的拉请求数0
关闭的拉请求数160
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?