Got

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

Github stars Tracking Chart

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

Main metrics

Overview
Name With Ownersindresorhus/got
Primary LanguageTypeScript
Program languageTypeScript (Language Count: 1)
PlatformLinux, Mac, Windows
License:MIT License
所有者活动
Created At2014-03-27 22:40:49
Pushed At2025-03-31 14:47:32
Last Commit At
Release Count178
Last Release Namev14.4.7 (Posted on 2025-03-31 20:04:25)
First Release Namev0.1.0 (Posted on 2014-03-27 23:43:16)
用户参与
Stargazers Count14.6k
Watchers Count111
Fork Count1k
Commits Count1.5k
Has Issues Enabled
Issues Count1473
Issue Open Count127
Pull Requests Count537
Pull Requests Open Count0
Pull Requests Close Count160
项目设置
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private