Socket
Socket
Sign inDemoInstall

got

Package Overview
Dependencies
30
Maintainers
2
Versions
172
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    got

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


Version published
Weekly downloads
20M
increased by1.5%
Maintainers
2
Install size
2.33 MB
Created
Weekly downloads
 

Package description

What is got?

The 'got' npm package is a human-friendly and powerful HTTP request library for Node.js. It provides an easy-to-use API for making HTTP requests and supports many features like streams, pagination, JSON parsing, and more.

What are got's main functionalities?

Simplified HTTP requests

This feature allows you to perform HTTP GET requests with a promise-based API. The example shows how to fetch a webpage and log the HTML content.

const got = require('got');
got('https://sindresorhus.com').then(response => {
  console.log(response.body);
}).catch(error => {
  console.log(error.response.body);
});

JSON support

This feature automatically parses JSON responses. The example demonstrates fetching JSON data from an API and logging the parsed object.

const got = require('got');
got('https://api.example.com/data', { responseType: 'json' }).then(response => {
  console.log(response.body);
}).catch(error => {
  console.log(error.response.body);
});

POST requests

This feature allows you to send POST requests with JSON bodies. The example shows how to send a POST request with a JSON payload and receive a JSON response.

const got = require('got');
got.post('https://api.example.com/submit', {
  json: {
    key: 'value'
  },
  responseType: 'json'
}).then(response => {
  console.log(response.body);
}).catch(error => {
  console.log(error.response.body);
});

Error handling

This feature provides comprehensive error handling for various types of request failures. The example demonstrates how to handle different error scenarios when a request fails.

const got = require('got');
got('https://api.example.com/wrong-endpoint').then(response => {
  console.log(response.body);
}).catch(error => {
  if (error.response) {
    console.log('The server responded with a non-2xx status code.');
  } else if (error.request) {
    console.log('The request was made but no response was received');
  } else {
    console.log('An error occurred when trying to perform the request.');
  }
});

Stream support

This feature allows you to use got as a stream. The example shows how to stream a webpage's content and write it to a file.

const got = require('got');
const fs = require('fs');
const stream = got.stream('https://sindresorhus.com');
stream.pipe(fs.createWriteStream('index.html'));

Other packages similar to got

Readme

Source


Got


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




Strapi
Strapi is the leading open-source headless CMS.
It’s 100% JavaScript, fully customizable, and developer-first.


Find the cheapest way to send money abroad



Keygen
A dead-simple software licensing and distribution API built for developers



Anvil

Paperwork that makes the data work.
Easy APIs for paperwork. PDF generation, e-signature and embeddable no-code webforms.
The easiest way to build paperwork automation into your product.
Anvil

Paperwork that makes the data work.
Easy APIs for paperwork. PDF generation, e-signature and embeddable no-code webforms.
The easiest way to build paperwork automation into your product.






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

Downloads Install size

See how Got compares to other HTTP libraries


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


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'll have to convert to ESM or use the dynamic import() function. Please don't open issues for questions regarding CommonJS / ESM. You can also use Got v11 instead which is pretty stable. We will backport security fixes to v11 for the foreseeable future.

Take a peek

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

  • 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

Legacy

  • travis-got - Got convenience wrapper to interact with the Travis API
  • graphql-got - Got convenience wrapper to interact with GraphQL

Comparison

gotrequestnode-fetchkyaxiossuperagent
HTTP/2 support:heavy_check_mark:¹:x::x::x::x::heavy_check_mark:**
Browser support:x::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::heavy_check_mark:
Stream API:heavy_check_mark::heavy_check_mark:Node.js only:x::x::heavy_check_mark:
Pagination API:heavy_check_mark::x::x::x::x::x:
Request cancelation:heavy_check_mark::x::heavy_check_mark::heavy_check_mark::heavy_check_mark::heavy_check_mark:
RFC compliant caching:heavy_check_mark::x::x::x::x::x:
Cookies (out-of-box):heavy_check_mark::heavy_check_mark::x::x::x::x:
Follows redirects:heavy_check_mark::heavy_check_mark::heavy_check_mark::heavy_check_mark::heavy_check_mark::heavy_check_mark:
Retries on failure:heavy_check_mark::x::x::heavy_check_mark::x::heavy_check_mark:
Progress events:heavy_check_mark::x::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::heavy_check_mark:
Advanced timeouts:heavy_check_mark::x::x::x::x::x:
Timings:heavy_check_mark::heavy_check_mark::x::x::x::x:
Errors with metadata:heavy_check_mark::x::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::heavy_check_mark:
Custom defaults:heavy_check_mark::heavy_check_mark::x::heavy_check_mark::heavy_check_mark::x:
Composable:heavy_check_mark::x::x::x::x::heavy_check_mark:
Hooks:heavy_check_mark::x::x::heavy_check_mark::heavy_check_mark::x:
Issues open
Issues closed
Downloads
CoverageTBD
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.
: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 SorhusSzymon Marczak
Sindre SorhusSzymon Marczak
Former

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 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

For enterprise

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.

Keywords

FAQs

Last updated on 06 Aug 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc