got

  • Version 12.0.1
  • Published
  • 244 kB
  • 13 dependencies
  • MIT license

Install

npm i got
yarn add got
pnpm add got

Overview

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

Index

Variables

Functions

Classes

Interfaces

Type Aliases

Variables

variable calculateRetryDelay

const calculateRetryDelay: Returns<RetryFunction, number>;

    variable got

    const got: Got;

      Functions

      function create

      create: (defaults: InstanceDefaults) => Got;

        function isResponseOk

        isResponseOk: (response: PlainResponse) => boolean;

          function parseBody

          parseBody: (
          response: Response,
          responseType: ResponseType,
          parseJson: ParseJsonFunction,
          encoding?: BufferEncoding | undefined
          ) => unknown;

            function parseLinkHeader

            parseLinkHeader: (
            link: string
            ) => { reference: string; parameters: Record<string, string> }[];

              Classes

              class CacheError

              class CacheError extends RequestError {}
              • An error to be thrown when a cache method fails. For example, if the database goes down or there's a filesystem error.

              constructor

              constructor(error: any, request: Request);

                property request

                readonly request: Request;

                  class CancelError

                  class CancelError extends RequestError {}
                  • An error to be thrown when the request is aborted with .cancel().

                  constructor

                  constructor(request: Request);

                    property isCanceled

                    readonly isCanceled: boolean;
                    • Whether the promise is canceled.

                    property response

                    readonly response: Response<unknown>;

                      class HTTPError

                      class HTTPError extends RequestError {}
                      • An error to be thrown when the server response code is not 2xx nor 3xx if options.followRedirect is true, but always except for 304. Includes a response property.

                      constructor

                      constructor(response: PlainResponse);

                        property request

                        readonly request: Request;

                          property response

                          readonly response: Response<unknown>;

                            property timings

                            readonly timings: any;

                              class MaxRedirectsError

                              class MaxRedirectsError extends RequestError {}
                              • An error to be thrown when the server redirects you more than ten times. Includes a response property.

                              constructor

                              constructor(request: Request);

                                property request

                                readonly request: Request;

                                  property response

                                  readonly response: Response<unknown>;

                                    property timings

                                    readonly timings: any;

                                      class Options

                                      class Options {}

                                        constructor

                                        constructor(input?: any, options?: OptionsInit, defaults?: Options);

                                          property agent

                                          agent: Agents;
                                          • An object representing http, https and http2 keys for [http.Agent](https://nodejs.org/api/http.html#http_class_http_agent), [https.Agent](https://nodejs.org/api/https.html#https_class_https_agent) and [http2wrapper.Agent](https://github.com/szmarczak/http2-wrapper#new-http2agentoptions) instance. This is necessary because a request to one protocol might redirect to another. In such a scenario, Got will switch over to the right protocol agent for you.

                                            If a key is not present, it will default to a global agent.

                                            Example 1

                                            ``` import got from 'got'; import HttpAgent from 'agentkeepalive';

                                            const {HttpsAgent} = HttpAgent;

                                            await got('https://sindresorhus.com', { agent: { http: new HttpAgent(), https: new HttpsAgent() } }); ```

                                          property allowGetBody

                                          allowGetBody: boolean;
                                          • Set this to true to allow sending body for the GET method. However, the [HTTP/2 specification](https://tools.ietf.org/html/rfc7540#section-8.1.3) says that An HTTP GET request includes request header fields and no payload body, therefore when using the HTTP/2 protocol this option will have no effect. This option is only meant to interact with non-compliant servers when you have no other choice.

                                            __Note__: The [RFC 7321](https://tools.ietf.org/html/rfc7231#section-4.3.1) doesn't specify any particular behavior for the GET method having a payload, therefore __it's considered an [anti-pattern](https://en.wikipedia.org/wiki/Anti-pattern)__.

                                            false

                                          property auth

                                          auth: {};

                                            property body

                                            body: any;
                                            • __Note #1__: The body option cannot be used with the json or form option.

                                              __Note #2__: If you provide this option, got.stream() will be read-only.

                                              __Note #3__: If you provide a payload with the GET or HEAD method, it will throw a TypeError unless the method is GET and the allowGetBody option is set to true.

                                              __Note #4__: This option is not enumerable and will not be merged with the instance defaults.

                                              The content-length header will be automatically set if body is a string / Buffer / [FormData](https://developer.mozilla.org/en-US/docs/Web/API/FormData) / [form-data instance](https://github.com/form-data/form-data), and content-length and transfer-encoding are not manually set in options.headers.

                                              Since Got 12, the content-length is not automatically set when body is a fs.createReadStream.

                                            property cache

                                            cache: any;
                                            • A cache adapter instance for storing cached response data.

                                              false

                                            property cacheOptions

                                            cacheOptions: CacheOptions;
                                            • From http-cache-semantics

                                              {}

                                            property context

                                            context: Record<string, unknown>;
                                            • User data. context is shallow merged and enumerable. If it contains non-enumerable properties they will NOT be merged.

                                              Example 1

                                              ``` import got from 'got';

                                              const instance = got.extend({ hooks: { beforeRequest: [ options => { if (!options.context || !options.context.token) { throw new Error('Token required'); }

                                              options.headers.token = options.context.token; } ] } });

                                              const context = { token: 'secret' };

                                              const response = await instance('https://httpbin.org/headers', {context});

                                              // Let's see the headers console.log(response.body); ```

                                            property cookieJar

                                            cookieJar: PromiseCookieJar | ToughCookieJar;
                                            • Cookie support. You don't have to care about parsing or how to store them.

                                              __Note__: If you provide this option, options.headers.cookie will be overridden.

                                            property createConnection

                                            createConnection: CreateConnectionFunction;

                                              property decompress

                                              decompress: boolean;
                                              • Decompress the response automatically.

                                                This will set the accept-encoding header to gzip, deflate, br unless you set it yourself.

                                                If this is disabled, a compressed response is returned as a Buffer. This may be useful if you want to handle decompression yourself or stream the raw compressed data.

                                                true

                                              property dnsCache

                                              dnsCache: any;
                                              • An instance of [CacheableLookup](https://github.com/szmarczak/cacheable-lookup) used for making DNS lookups. Useful when making lots of requests to different *public* hostnames.

                                                CacheableLookup uses dns.resolver4(..) and dns.resolver6(...) under the hood and fall backs to dns.lookup(...) when the first two fail, which may lead to additional delay.

                                                __Note__: This should stay disabled when making requests to internal hostnames such as localhost, database.local etc.

                                                false

                                              property dnsLookup

                                              dnsLookup: any;

                                                property dnsLookupIpVersion

                                                dnsLookupIpVersion: DnsLookupIpVersion;
                                                • Indicates which DNS record family to use.

                                                  Values: - undefined: IPv4 (if present) or IPv6 - 4: Only IPv4 - 6: Only IPv6

                                                  undefined

                                                property encoding

                                                encoding: any;
                                                • [Encoding](https://nodejs.org/api/buffer.html#buffer_buffers_and_character_encodings) to be used on setEncoding of the response data.

                                                  To get a [Buffer](https://nodejs.org/api/buffer.html), you need to set responseType to buffer instead. Don't set this option to null.

                                                  __Note__: This doesn't affect streams! Instead, you need to do got.stream(...).setEncoding(encoding).

                                                  'utf-8'

                                                property followRedirect

                                                followRedirect: boolean;
                                                • Defines if redirect responses should be followed automatically.

                                                  Note that if a 303 is sent by the server in response to any request type (POST, DELETE, etc.), Got will automatically request the resource pointed to in the location header via GET. This is in accordance with [the spec](https://tools.ietf.org/html/rfc7231#section-6.4.4).

                                                  true

                                                property followRedirects

                                                followRedirects: {};

                                                  property form

                                                  form: Record<string, any>;
                                                  • The form body is converted to a query string using [(new URLSearchParams(object)).toString()](https://nodejs.org/api/url.html#url_constructor_new_urlsearchparams_obj).

                                                    If the Content-Type header is not present, it will be set to application/x-www-form-urlencoded.

                                                    __Note #1__: If you provide this option, got.stream() will be read-only.

                                                    __Note #2__: This option is not enumerable and will not be merged with the instance defaults.

                                                  property h2session

                                                  h2session: any;

                                                    property headers

                                                    headers: Headers;
                                                    • Request headers.

                                                      Existing headers will be overwritten. Headers set to undefined will be omitted.

                                                      {}

                                                    property hooks

                                                    hooks: Hooks;
                                                    • Hooks allow modifications during the request lifecycle. Hook functions may be async and are run serially.

                                                    property http2

                                                    http2: boolean;
                                                    • If set to true, Got will additionally accept HTTP2 requests.

                                                      It will choose either HTTP/1.1 or HTTP/2 depending on the ALPN protocol.

                                                      __Note__: This option requires Node.js 15.10.0 or newer as HTTP/2 support on older Node.js versions is very buggy.

                                                      __Note__: Overriding options.request will disable HTTP2 support.

                                                      false

                                                      Example 1

                                                      ``` import got from 'got';

                                                      const {headers} = await got('https://nghttp2.org/httpbin/anything', {http2: true});

                                                      console.log(headers.via); //=> '2 nghttpx' ```

                                                    property https

                                                    https: HttpsOptions;
                                                    • Options for the advanced HTTPS API.

                                                    property ignoreInvalidCookies

                                                    ignoreInvalidCookies: boolean;
                                                    • Ignore invalid cookies instead of throwing an error. Only useful when the cookieJar option has been set. Not recommended.

                                                      false

                                                    property isStream

                                                    isStream: boolean;
                                                    • Returns a Stream instead of a Promise. This is equivalent to calling got.stream(url, options?).

                                                      false

                                                    property json

                                                    json: Record<string, any>;
                                                    • JSON body. If the Content-Type header is not set, it will be set to application/json.

                                                      __Note #1__: If you provide this option, got.stream() will be read-only.

                                                      __Note #2__: This option is not enumerable and will not be merged with the instance defaults.

                                                    property localAddress

                                                    localAddress: string;
                                                    • From http.RequestOptions.

                                                      The IP address used to send the request from.

                                                    property maxHeaderSize

                                                    maxHeaderSize: number;

                                                      property maxRedirects

                                                      maxRedirects: number;
                                                      • If exceeded, the request will be aborted and a MaxRedirectsError will be thrown.

                                                        10

                                                      property method

                                                      method: Method;
                                                      • The HTTP method used to make the request.

                                                        'GET'

                                                      property methodRewriting

                                                      methodRewriting: boolean;
                                                      • Specifies if the redirects should be [rewritten as GET](https://tools.ietf.org/html/rfc7231#section-6.4).

                                                        If false, when sending a POST request and receiving a 302, it will resend the body to the new location using the same HTTP method (POST in this case).

                                                        false

                                                      property pagination

                                                      pagination: PaginationOptions<unknown, unknown>;

                                                        property parseJson

                                                        parseJson: ParseJsonFunction;
                                                        • A function used to parse JSON responses.

                                                          Example 1

                                                          ``` import got from 'got'; import Bourne from '@hapi/bourne';

                                                          const parsed = await got('https://example.com', { parseJson: text => Bourne.parse(text) }).json();

                                                          console.log(parsed); ```

                                                        property password

                                                        password: string;

                                                          property prefixUrl

                                                          prefixUrl: any;
                                                          • When specified, prefixUrl will be prepended to url. The prefix can be any valid URL, either relative or absolute. A trailing slash / is optional - one will be added automatically.

                                                            __Note__: prefixUrl will be ignored if the url argument is a URL instance.

                                                            __Note__: Leading slashes in input are disallowed when using this option to enforce consistency and avoid confusion. For example, when the prefix URL is https://example.com/foo and the input is /bar, there's ambiguity whether the resulting URL would become https://example.com/foo/bar or https://example.com/bar. The latter is used by browsers.

                                                            __Tip__: Useful when used with got.extend() to create niche-specific Got instances.

                                                            __Tip__: You can change prefixUrl using hooks as long as the URL still includes the prefixUrl. If the URL doesn't include it anymore, it will throw.

                                                            Example 1

                                                            ``` import got from 'got';

                                                            await got('unicorn', {prefixUrl: 'https://cats.com'}); //=> 'https://cats.com/unicorn'

                                                            const instance = got.extend({ prefixUrl: 'https://google.com' });

                                                            await instance('unicorn', { hooks: { beforeRequest: [ options => { options.prefixUrl = 'https://cats.com'; } ] } }); //=> 'https://cats.com/unicorn' ```

                                                          property request

                                                          request: RequestFunction;
                                                          • Custom request function. The main purpose of this is to [support HTTP2 using a wrapper](https://github.com/szmarczak/http2-wrapper).

                                                            http.request | https.request

                                                          property resolveBodyOnly

                                                          resolveBodyOnly: boolean;
                                                          • When set to true the promise will return the Response body instead of the Response object.

                                                            false

                                                          property responseType

                                                          responseType: ResponseType;
                                                          • The parsing method.

                                                            The promise also has .text(), .json() and .buffer() methods which return another Got promise for the parsed body.

                                                            It's like setting the options to {responseType: 'json', resolveBodyOnly: true} but without affecting the main Got promise.

                                                            __Note__: When using streams, this option is ignored.

                                                            Example 1

                                                            ``` const responsePromise = got(url); const bufferPromise = responsePromise.buffer(); const jsonPromise = responsePromise.json();

                                                            const [response, buffer, json] = Promise.all([responsePromise, bufferPromise, jsonPromise]); // response is an instance of Got Response // buffer is an instance of Buffer // json is an object ```

                                                            Example 2

                                                            ``` // This const body = await got(url).json();

                                                            // is semantically the same as this const body = await got(url, {responseType: 'json', resolveBodyOnly: true}); ```

                                                          property retry

                                                          retry: Partial<RetryOptions>;
                                                          • An object representing limit, calculateDelay, methods, statusCodes, maxRetryAfter and errorCodes fields for maximum retry count, retry handler, allowed methods, allowed status codes, maximum [Retry-After](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After) time and allowed error codes.

                                                            Delays between retries counts with function 1000 * Math.pow(2, retry) + Math.random() * 100, where retry is attempt number (starts from 1).

                                                            The calculateDelay property is a function that receives an object with attemptCount, retryOptions, error and computedValue properties for current retry count, the retry options, error and default computed value. The function must return a delay in milliseconds (or a Promise resolving with it) (0 return value cancels retry).

                                                            By default, it retries *only* on the specified methods, status codes, and on these network errors:

                                                            - ETIMEDOUT: One of the [timeout](#timeout) limits were reached. - ECONNRESET: Connection was forcibly closed by a peer. - EADDRINUSE: Could not bind to any free port. - ECONNREFUSED: Connection was refused by the server. - EPIPE: The remote side of the stream being written has been closed. - ENOTFOUND: Couldn't resolve the hostname to an IP address. - ENETUNREACH: No internet connection. - EAI_AGAIN: DNS lookup timed out.

                                                            __Note__: If maxRetryAfter is set to undefined, it will use options.timeout. __Note__: If [Retry-After](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After) header is greater than maxRetryAfter, it will cancel the request.

                                                          property searchParameters

                                                          searchParameters: {};

                                                            property searchParams

                                                            searchParams: any;
                                                            • Query string that will be added to the request URL. This will override the query string in url.

                                                              If you need to pass in an array, you can do it using a URLSearchParams instance.

                                                              Example 1

                                                              ``` import got from 'got';

                                                              const searchParams = new URLSearchParams([['key', 'a'], ['key', 'b']]);

                                                              await got('https://example.com', {searchParams});

                                                              console.log(searchParams.toString()); //=> 'key=a&key=b' ```

                                                            property setHost

                                                            setHost: boolean;

                                                              property stringifyJson

                                                              stringifyJson: StringifyJsonFunction;
                                                              • A function used to stringify the body of JSON requests.

                                                                Example 1

                                                                ``` import got from 'got';

                                                                await got.post('https://example.com', { stringifyJson: object => JSON.stringify(object, (key, value) => { if (key.startsWith('_')) { return; }

                                                                return value; }), json: { some: 'payload', _ignoreMe: 1234 } }); ```

                                                                Example 2

                                                                ``` import got from 'got';

                                                                await got.post('https://example.com', { stringifyJson: object => JSON.stringify(object, (key, value) => { if (typeof value === 'number') { return value.toString(); }

                                                                return value; }), json: { some: 'payload', number: 1 } }); ```

                                                              property throwHttpErrors

                                                              throwHttpErrors: boolean;
                                                              • Determines if a got.HTTPError is thrown for unsuccessful responses.

                                                                If this is disabled, requests that encounter an error status code will be resolved with the response instead of throwing. This may be useful if you are checking for resource availability and are expecting error responses.

                                                                true

                                                              property timeout

                                                              timeout: Delays;
                                                              • Milliseconds to wait for the server to end the response before aborting the request with got.TimeoutError error (a.k.a. request property). By default, there's no timeout.

                                                                This also accepts an object with the following fields to constrain the duration of each phase of the request lifecycle:

                                                                - lookup starts when a socket is assigned and ends when the hostname has been resolved. Does not apply when using a Unix domain socket. - connect starts when lookup completes (or when the socket is assigned if lookup does not apply to the request) and ends when the socket is connected. - secureConnect starts when connect completes and ends when the handshaking process completes (HTTPS only). - socket starts when the socket is connected. See [request.setTimeout](https://nodejs.org/api/http.html#http_request_settimeout_timeout_callback). - response starts when the request has been written to the socket and ends when the response headers are received. - send starts when the socket is connected and ends with the request has been written to the socket. - request starts when the request is initiated and ends when the response's end event fires.

                                                              property url

                                                              url: any;
                                                              • The URL to request, as a string, a [https.request options object](https://nodejs.org/api/https.html#https_https_request_options_callback), or a [WHATWG URL](https://nodejs.org/api/url.html#url_class_url).

                                                                Properties from options will override properties in the parsed url.

                                                                If no protocol is specified, it will throw a TypeError.

                                                                __Note__: The query string is **not** parsed as search params.

                                                                Example 1

                                                                ``` await got('https://example.com/?query=a b'); //=> https://example.com/?query=a%20b await got('https://example.com/', {searchParams: {query: 'a b'}}); //=> https://example.com/?query=a+b

                                                                // The query string is overridden by searchParams await got('https://example.com/?query=a b', {searchParams: {query: 'a b'}}); //=> https://example.com/?query=a+b ```

                                                              property username

                                                              username: string;

                                                                method createNativeRequestOptions

                                                                createNativeRequestOptions: () => {
                                                                ALPNProtocols: string[] | undefined;
                                                                ca: string | Buffer | (string | Buffer)[] | undefined;
                                                                cert: string | Buffer | (string | Buffer)[] | undefined;
                                                                key: string | Buffer | (Buffer | import('tls').KeyObject)[] | undefined;
                                                                passphrase: string | undefined;
                                                                pfx: PfxType;
                                                                rejectUnauthorized: boolean | undefined;
                                                                checkServerIdentity:
                                                                | CheckServerIdentityFunction
                                                                | typeof checkServerIdentity;
                                                                ciphers: string | undefined;
                                                                honorCipherOrder: boolean | undefined;
                                                                minVersion: import('tls').SecureVersion | undefined;
                                                                maxVersion: import('tls').SecureVersion | undefined;
                                                                sigalgs: string | undefined;
                                                                sessionTimeout: number | undefined;
                                                                dhparam: string | Buffer | undefined;
                                                                ecdhCurve: string | undefined;
                                                                crl: string | Buffer | (string | Buffer)[] | undefined;
                                                                lookup: {
                                                                (
                                                                hostname: string,
                                                                family: any,
                                                                callback: (
                                                                error: NodeJS.ErrnoException | null,
                                                                address: string,
                                                                family: any
                                                                ) => void
                                                                ): void;
                                                                (
                                                                hostname: string,
                                                                callback: (
                                                                error: NodeJS.ErrnoException | null,
                                                                address: string,
                                                                family: any
                                                                ) => void
                                                                ): void;
                                                                (
                                                                hostname: string,
                                                                options: import('cacheable-lookup').LookupOptions & { all: true },
                                                                callback: (
                                                                error: NodeJS.ErrnoException | null,
                                                                result: readonly import('cacheable-lookup').EntryObject[]
                                                                ) => void
                                                                ): void;
                                                                (
                                                                hostname: string,
                                                                options: any,
                                                                callback: (
                                                                error: NodeJS.ErrnoException | null,
                                                                address: string,
                                                                family: any
                                                                ) => void
                                                                ): void;
                                                                };
                                                                family: DnsLookupIpVersion;
                                                                agent: false | Agents | http.Agent | undefined;
                                                                setHost: boolean;
                                                                method: Method;
                                                                maxHeaderSize: number | undefined;
                                                                localAddress: string | undefined;
                                                                headers: Headers;
                                                                createConnection: CreateConnectionFunction | undefined;
                                                                timeout: number | undefined;
                                                                h2session: http2wrapper.ClientHttp2Session | undefined;
                                                                signal?: AbortSignal | undefined;
                                                                protocol?: string | null | undefined;
                                                                host?: string | null | undefined;
                                                                hostname?: string | null | undefined;
                                                                port?: string | number | null | undefined;
                                                                defaultPort?: string | number | undefined;
                                                                socketPath?: string | undefined;
                                                                path?: string | null | undefined;
                                                                auth?: string | null | undefined;
                                                                _defaultAgent?: http.Agent | undefined;
                                                                clientCertEngine?: string | undefined;
                                                                privateKeyEngine?: string | undefined;
                                                                privateKeyIdentifier?: string | undefined;
                                                                secureOptions?: number | undefined;
                                                                secureProtocol?: string | undefined;
                                                                sessionIdContext?: string | undefined;
                                                                ticketKeys?: Buffer | undefined;
                                                                servername?: string | undefined;
                                                                shared?: boolean | undefined;
                                                                cacheHeuristic?: number | undefined;
                                                                immutableMinTimeToLive?: number | undefined;
                                                                ignoreCargoCult?: boolean | undefined;
                                                                };

                                                                  method freeze

                                                                  freeze: () => void;

                                                                    method getFallbackRequestFunction

                                                                    getFallbackRequestFunction: () =>
                                                                    | RequestFunction
                                                                    | typeof https.request
                                                                    | undefined;

                                                                      method getRequestFunction

                                                                      getRequestFunction: () => RequestFunction | typeof https.request | undefined;

                                                                        method merge

                                                                        merge: (options?: OptionsInit | Options) => void;

                                                                          method toJSON

                                                                          toJSON: () => {
                                                                          headers: Headers;
                                                                          timeout: Delays;
                                                                          request: RequestFunction | undefined;
                                                                          username: string;
                                                                          password: string;
                                                                          json: Record<string, any> | undefined;
                                                                          retry: Partial<RetryOptions>;
                                                                          agent: Agents;
                                                                          h2session: http2wrapper.ClientHttp2Session | undefined;
                                                                          decompress: boolean;
                                                                          prefixUrl: string | URL;
                                                                          body:
                                                                          | string
                                                                          | Readable
                                                                          | Buffer
                                                                          | Generator<unknown, any, unknown>
                                                                          | AsyncGenerator<unknown, any, unknown>
                                                                          | FormDataLike
                                                                          | undefined;
                                                                          form: Record<string, any> | undefined;
                                                                          url: string | URL | undefined;
                                                                          cookieJar: PromiseCookieJar | ToughCookieJar | undefined;
                                                                          ignoreInvalidCookies: boolean;
                                                                          searchParams: string | SearchParameters | URLSearchParams | undefined;
                                                                          dnsLookup: {
                                                                          (
                                                                          hostname: string,
                                                                          family: any,
                                                                          callback: (
                                                                          error: NodeJS.ErrnoException | null,
                                                                          address: string,
                                                                          family: any
                                                                          ) => void
                                                                          ): void;
                                                                          (
                                                                          hostname: string,
                                                                          callback: (
                                                                          error: NodeJS.ErrnoException | null,
                                                                          address: string,
                                                                          family: any
                                                                          ) => void
                                                                          ): void;
                                                                          (
                                                                          hostname: string,
                                                                          options: import('cacheable-lookup').LookupOptions & { all: true },
                                                                          callback: (
                                                                          error: NodeJS.ErrnoException | null,
                                                                          result: readonly import('cacheable-lookup').EntryObject[]
                                                                          ) => void
                                                                          ): void;
                                                                          (
                                                                          hostname: string,
                                                                          options: any,
                                                                          callback: (
                                                                          error: NodeJS.ErrnoException | null,
                                                                          address: string,
                                                                          family: any
                                                                          ) => void
                                                                          ): void;
                                                                          };
                                                                          dnsCache: boolean | CacheableLookup | undefined;
                                                                          context: Record<string, unknown>;
                                                                          hooks: Hooks;
                                                                          followRedirect: boolean;
                                                                          maxRedirects: number;
                                                                          cache: string | boolean | CacheableRequest.StorageAdapter | undefined;
                                                                          throwHttpErrors: boolean;
                                                                          http2: boolean;
                                                                          allowGetBody: boolean;
                                                                          methodRewriting: boolean;
                                                                          dnsLookupIpVersion: DnsLookupIpVersion;
                                                                          parseJson: ParseJsonFunction;
                                                                          stringifyJson: StringifyJsonFunction;
                                                                          localAddress: string | undefined;
                                                                          method: Method;
                                                                          createConnection: CreateConnectionFunction | undefined;
                                                                          cacheOptions: CacheOptions;
                                                                          https: HttpsOptions;
                                                                          encoding: BufferEncoding | undefined;
                                                                          resolveBodyOnly: boolean;
                                                                          isStream: boolean;
                                                                          responseType: ResponseType;
                                                                          pagination: PaginationOptions<unknown, unknown>;
                                                                          setHost: boolean;
                                                                          maxHeaderSize: number | undefined;
                                                                          };

                                                                            class ParseError

                                                                            class ParseError extends RequestError {}
                                                                            • An error to be thrown when server response code is 2xx, and parsing body fails. Includes a response property.

                                                                            constructor

                                                                            constructor(error: Error, response: Response<unknown>);

                                                                              property response

                                                                              readonly response: Response<unknown>;

                                                                                class ReadError

                                                                                class ReadError extends RequestError {}
                                                                                • An error to be thrown when reading from response stream fails.

                                                                                constructor

                                                                                constructor(error: any, request: Request);

                                                                                  property request

                                                                                  readonly request: Request;

                                                                                    property response

                                                                                    readonly response: Response<unknown>;

                                                                                      property timings

                                                                                      readonly timings: any;

                                                                                        class Request

                                                                                        class Request extends Duplex implements RequestEvents<Request> {}

                                                                                          constructor

                                                                                          constructor(url: any, options?: OptionsInit, defaults?: Options);

                                                                                            property ['constructor']

                                                                                            ['constructor']: typeof Request;

                                                                                              property downloadProgress

                                                                                              readonly downloadProgress: Progress;
                                                                                              • Progress event for downloading (receiving a response).

                                                                                              property ip

                                                                                              readonly ip: string;
                                                                                              • The remote IP address.

                                                                                              property isAborted

                                                                                              readonly isAborted: boolean;
                                                                                              • Indicates whether the request has been aborted or not.

                                                                                              property isFromCache

                                                                                              readonly isFromCache: boolean;
                                                                                              • Whether the response was retrieved from the cache.

                                                                                              property options

                                                                                              options: Options;

                                                                                                property redirectUrls

                                                                                                redirectUrls: any[];

                                                                                                  property requestUrl

                                                                                                  requestUrl?: any;

                                                                                                    property response

                                                                                                    response?: PlainResponse;

                                                                                                      property retryCount

                                                                                                      retryCount: number;

                                                                                                        property reusedSocket

                                                                                                        readonly reusedSocket: boolean;

                                                                                                          property socket

                                                                                                          readonly socket: any;

                                                                                                            property timings

                                                                                                            readonly timings: any;
                                                                                                            • The object contains the following properties:

                                                                                                              - start - Time when the request started. - socket - Time when a socket was assigned to the request. - lookup - Time when the DNS lookup finished. - connect - Time when the socket successfully connected. - secureConnect - Time when the socket securely connected. - upload - Time when the request finished uploading. - response - Time when the request fired response event. - end - Time when the response fired end event. - error - Time when the request fired error event. - abort - Time when the request fired abort event. - phases - wait - timings.socket - timings.start - dns - timings.lookup - timings.socket - tcp - timings.connect - timings.lookup - tls - timings.secureConnect - timings.connect - request - timings.upload - (timings.secureConnect || timings.connect) - firstByte - timings.response - timings.upload - download - timings.end - timings.response - total - (timings.end || timings.error || timings.abort) - timings.start

                                                                                                              If something has not been measured yet, it will be undefined.

                                                                                                              __Note__: The time is a number representing the milliseconds elapsed since the UNIX epoch.

                                                                                                            property uploadProgress

                                                                                                            readonly uploadProgress: Progress;
                                                                                                            • Progress event for uploading (sending a request).

                                                                                                            method flush

                                                                                                            flush: () => Promise<void>;

                                                                                                              method pipe

                                                                                                              pipe: <T extends any>(destination: T, options?: { end?: boolean }) => T;

                                                                                                                method unpipe

                                                                                                                unpipe: <T extends any>(destination: T) => this;

                                                                                                                  class RequestError

                                                                                                                  class RequestError extends Error {}
                                                                                                                  • An error to be thrown when a request fails. Contains a code property with error class code, like ECONNREFUSED.

                                                                                                                  constructor

                                                                                                                  constructor(message: string, error: Partial<any>, self: Options | Request);

                                                                                                                    property code

                                                                                                                    code: string;

                                                                                                                      property input

                                                                                                                      input?: string;

                                                                                                                        property options

                                                                                                                        readonly options: Options;

                                                                                                                          property request

                                                                                                                          readonly request?: Request;

                                                                                                                            property response

                                                                                                                            readonly response?: Response<unknown>;

                                                                                                                              property stack

                                                                                                                              stack: string;

                                                                                                                                property timings

                                                                                                                                readonly timings?: any;

                                                                                                                                  class RetryError

                                                                                                                                  class RetryError extends RequestError {}
                                                                                                                                  • An error which always triggers a new retry when thrown.

                                                                                                                                  constructor

                                                                                                                                  constructor(request: Request);

                                                                                                                                    class TimeoutError

                                                                                                                                    class TimeoutError extends RequestError {}
                                                                                                                                    • An error to be thrown when the request is aborted due to a timeout. Includes an event and timings property.

                                                                                                                                    constructor

                                                                                                                                    constructor(error: TimedOutTimeoutError, timings: any, request: Request);

                                                                                                                                      property event

                                                                                                                                      readonly event: string;

                                                                                                                                        property request

                                                                                                                                        readonly request: Request;

                                                                                                                                          property timings

                                                                                                                                          readonly timings: any;

                                                                                                                                            class UploadError

                                                                                                                                            class UploadError extends RequestError {}
                                                                                                                                            • An error to be thrown when the request body is a stream and an error occurs while reading from that stream.

                                                                                                                                            constructor

                                                                                                                                            constructor(error: any, request: Request);

                                                                                                                                              property request

                                                                                                                                              readonly request: Request;

                                                                                                                                                Interfaces

                                                                                                                                                interface Agents

                                                                                                                                                interface Agents {}

                                                                                                                                                  property http

                                                                                                                                                  http?: HttpAgent | false;

                                                                                                                                                    property http2

                                                                                                                                                    http2?: unknown | false;

                                                                                                                                                      property https

                                                                                                                                                      https?: HttpsAgent | false;

                                                                                                                                                        interface CacheOptions

                                                                                                                                                        interface CacheOptions {}

                                                                                                                                                          property cacheHeuristic

                                                                                                                                                          cacheHeuristic?: number;

                                                                                                                                                            property ignoreCargoCult

                                                                                                                                                            ignoreCargoCult?: boolean;

                                                                                                                                                              property immutableMinTimeToLive

                                                                                                                                                              immutableMinTimeToLive?: number;

                                                                                                                                                                property shared

                                                                                                                                                                shared?: boolean;

                                                                                                                                                                  interface CancelableRequest

                                                                                                                                                                  interface CancelableRequest<T extends Response | Response['body'] = Response['body']>
                                                                                                                                                                  extends PCancelable<T>,
                                                                                                                                                                  RequestEvents<CancelableRequest<T>> {}

                                                                                                                                                                    property buffer

                                                                                                                                                                    buffer: () => CancelableRequest<Buffer>;
                                                                                                                                                                    • A shortcut method that gives a Promise returning a [Buffer](https://nodejs.org/api/buffer.html).

                                                                                                                                                                      It is semantically the same as settings options.resolveBodyOnly to true and options.responseType to 'buffer'.

                                                                                                                                                                    property json

                                                                                                                                                                    json: <ReturnType>() => CancelableRequest<ReturnType>;
                                                                                                                                                                    • A shortcut method that gives a Promise returning a JSON object.

                                                                                                                                                                      It is semantically the same as settings options.resolveBodyOnly to true and options.responseType to 'json'.

                                                                                                                                                                    property text

                                                                                                                                                                    text: () => CancelableRequest<string>;
                                                                                                                                                                    • A shortcut method that gives a Promise returning a string.

                                                                                                                                                                      It is semantically the same as settings options.resolveBodyOnly to true and options.responseType to 'text'.

                                                                                                                                                                    interface Delays

                                                                                                                                                                    interface Delays {}

                                                                                                                                                                      property connect

                                                                                                                                                                      connect?: number;

                                                                                                                                                                        property lookup

                                                                                                                                                                        lookup?: number;

                                                                                                                                                                          property read

                                                                                                                                                                          read?: number;

                                                                                                                                                                            property request

                                                                                                                                                                            request?: number;

                                                                                                                                                                              property response

                                                                                                                                                                              response?: number;

                                                                                                                                                                                property secureConnect

                                                                                                                                                                                secureConnect?: number;

                                                                                                                                                                                  property send

                                                                                                                                                                                  send?: number;

                                                                                                                                                                                    property socket

                                                                                                                                                                                    socket?: number;

                                                                                                                                                                                      interface ExtendOptions

                                                                                                                                                                                      interface ExtendOptions extends OptionsInit {}
                                                                                                                                                                                      • The options available for got.extend().

                                                                                                                                                                                      property handlers

                                                                                                                                                                                      handlers?: HandlerFunction[];
                                                                                                                                                                                      • An array of functions. You execute them directly by calling got(). They are some sort of "global hooks" - these functions are called first. The last handler (*it's hidden*) is either asPromise or asStream, depending on the options.isStream property.

                                                                                                                                                                                        []

                                                                                                                                                                                      property mutableDefaults

                                                                                                                                                                                      mutableDefaults?: boolean;
                                                                                                                                                                                      • A read-only boolean describing whether the defaults are mutable or not. If set to true, you can update headers over time, for example, update an access token when it expires.

                                                                                                                                                                                        false

                                                                                                                                                                                      interface FilterData

                                                                                                                                                                                      interface FilterData<ElementType> {}

                                                                                                                                                                                        property allItems

                                                                                                                                                                                        allItems: ElementType[];

                                                                                                                                                                                          property currentItems

                                                                                                                                                                                          currentItems: ElementType[];

                                                                                                                                                                                            property item

                                                                                                                                                                                            item: ElementType;

                                                                                                                                                                                              interface Got

                                                                                                                                                                                              interface Got extends Record<HTTPAlias, GotRequestFunction>, GotRequestFunction {}
                                                                                                                                                                                              • An instance of got.

                                                                                                                                                                                              property defaults

                                                                                                                                                                                              defaults: InstanceDefaults;
                                                                                                                                                                                              • The Got defaults used in that instance.

                                                                                                                                                                                              property extend

                                                                                                                                                                                              extend: (...instancesOrOptions: Array<Got | ExtendOptions>) => Got;
                                                                                                                                                                                              • Configure a new got instance with default options. The options are merged with the parent instance's defaults.options using got.mergeOptions. You can access the resolved options with the .defaults property on the instance.

                                                                                                                                                                                                Additionally, got.extend() accepts two properties from the defaults object: mutableDefaults and handlers.

                                                                                                                                                                                                It is also possible to merges many instances into a single one: - options are merged using got.mergeOptions() (including hooks), - handlers are stored in an array (you can access them through instance.defaults.handlers).

                                                                                                                                                                                                Example 1

                                                                                                                                                                                                ``` const client = got.extend({ prefixUrl: 'https://example.com', headers: { 'x-unicorn': 'rainbow' } });

                                                                                                                                                                                                client.get('demo');

                                                                                                                                                                                                // HTTP Request => // GET /demo HTTP/1.1 // Host: example.com // x-unicorn: rainbow ```

                                                                                                                                                                                              property paginate

                                                                                                                                                                                              paginate: GotPaginate;
                                                                                                                                                                                              • Returns an async iterator.

                                                                                                                                                                                                See pagination.options for more pagination options.

                                                                                                                                                                                                Example 1

                                                                                                                                                                                                ``` const countLimit = 10;

                                                                                                                                                                                                const pagination = got.paginate('https://api.github.com/repos/sindresorhus/got/commits', { pagination: {countLimit} });

                                                                                                                                                                                                console.log(Printing latest ${countLimit} Got commits (newest to oldest):);

                                                                                                                                                                                                for await (const commitData of pagination) { console.log(commitData.commit.message); } ```

                                                                                                                                                                                              property stream

                                                                                                                                                                                              stream: GotStream;
                                                                                                                                                                                              • Sets options.isStream to true.

                                                                                                                                                                                                Returns a [duplex stream](https://nodejs.org/api/stream.html#stream_class_stream_duplex) with additional events: - request - response - redirect - uploadProgress - downloadProgress - error

                                                                                                                                                                                              interface GotPaginate

                                                                                                                                                                                              interface GotPaginate {}
                                                                                                                                                                                              • An instance of got.paginate.

                                                                                                                                                                                              property all

                                                                                                                                                                                              all: (<T, R = unknown>(
                                                                                                                                                                                              url: string | URL,
                                                                                                                                                                                              options?: OptionsWithPagination<T, R>
                                                                                                                                                                                              ) => Promise<T[]>) &
                                                                                                                                                                                              (<T, R = unknown>(options?: OptionsWithPagination<T, R>) => Promise<T[]>);
                                                                                                                                                                                              • Returns a Promise for an array of all results.

                                                                                                                                                                                                See pagination.options for more pagination options.

                                                                                                                                                                                                Example 1

                                                                                                                                                                                                ``` const countLimit = 10;

                                                                                                                                                                                                const results = await got.paginate.all('https://api.github.com/repos/sindresorhus/got/commits', { pagination: {countLimit} });

                                                                                                                                                                                                console.log(Printing latest ${countLimit} Got commits (newest to oldest):); console.log(results); ```

                                                                                                                                                                                              property each

                                                                                                                                                                                              each: (<T, R = unknown>(
                                                                                                                                                                                              url: string | URL,
                                                                                                                                                                                              options?: OptionsWithPagination<T, R>
                                                                                                                                                                                              ) => AsyncIterableIterator<T>) &
                                                                                                                                                                                              (<T, R = unknown>(
                                                                                                                                                                                              options?: OptionsWithPagination<T, R>
                                                                                                                                                                                              ) => AsyncIterableIterator<T>);
                                                                                                                                                                                              • Returns an async iterator.

                                                                                                                                                                                                See pagination.options for more pagination options.

                                                                                                                                                                                                Example 1

                                                                                                                                                                                                ``` const countLimit = 10;

                                                                                                                                                                                                const pagination = got.paginate('https://api.github.com/repos/sindresorhus/got/commits', { pagination: {countLimit} });

                                                                                                                                                                                                console.log(Printing latest ${countLimit} Got commits (newest to oldest):);

                                                                                                                                                                                                for await (const commitData of pagination) { console.log(commitData.commit.message); } ```

                                                                                                                                                                                              call signature

                                                                                                                                                                                              <T, R = unknown>(
                                                                                                                                                                                              url: string | URL,
                                                                                                                                                                                              options?: OptionsWithPagination<T, R>
                                                                                                                                                                                              ): AsyncIterableIterator<T>;
                                                                                                                                                                                              • Same as GotPaginate.each.

                                                                                                                                                                                              call signature

                                                                                                                                                                                              <T, R = unknown>(
                                                                                                                                                                                              options?: OptionsWithPagination<T, R>
                                                                                                                                                                                              ): AsyncIterableIterator<T>;
                                                                                                                                                                                              • Same as GotPaginate.each.

                                                                                                                                                                                              interface GotRequestFunction

                                                                                                                                                                                              interface GotRequestFunction {}

                                                                                                                                                                                                call signature

                                                                                                                                                                                                (url: string | URL, options?: OptionsOfTextResponseBody): CancelableRequest<
                                                                                                                                                                                                Response<string>
                                                                                                                                                                                                >;

                                                                                                                                                                                                  call signature

                                                                                                                                                                                                  <T>(url: string | URL, options?: OptionsOfJSONResponseBody): CancelableRequest<
                                                                                                                                                                                                  Response<T>
                                                                                                                                                                                                  >;

                                                                                                                                                                                                    call signature

                                                                                                                                                                                                    (
                                                                                                                                                                                                    url: string | URL,
                                                                                                                                                                                                    options?: Merge<OptionsOfBufferResponseBody, ResponseBodyOnly>
                                                                                                                                                                                                    ): CancelableRequest<Buffer>;

                                                                                                                                                                                                      call signature

                                                                                                                                                                                                      (
                                                                                                                                                                                                      options: Merge<OptionsOfTextResponseBody, ResponseBodyOnly>
                                                                                                                                                                                                      ): CancelableRequest<string>;

                                                                                                                                                                                                        call signature

                                                                                                                                                                                                        <T>(
                                                                                                                                                                                                        options: Merge<OptionsOfJSONResponseBody, ResponseBodyOnly>
                                                                                                                                                                                                        ): CancelableRequest<T>;

                                                                                                                                                                                                          call signature

                                                                                                                                                                                                          (
                                                                                                                                                                                                          options: Merge<OptionsOfBufferResponseBody, ResponseBodyOnly>
                                                                                                                                                                                                          ): CancelableRequest<Buffer>;

                                                                                                                                                                                                            call signature

                                                                                                                                                                                                            (
                                                                                                                                                                                                            url: string | URL,
                                                                                                                                                                                                            options?: Merge<
                                                                                                                                                                                                            OptionsInit,
                                                                                                                                                                                                            {
                                                                                                                                                                                                            isStream: true;
                                                                                                                                                                                                            }
                                                                                                                                                                                                            >
                                                                                                                                                                                                            ): Request;

                                                                                                                                                                                                              call signature

                                                                                                                                                                                                              (
                                                                                                                                                                                                              options: Merge<
                                                                                                                                                                                                              OptionsInit,
                                                                                                                                                                                                              {
                                                                                                                                                                                                              isStream: true;
                                                                                                                                                                                                              }
                                                                                                                                                                                                              >
                                                                                                                                                                                                              ): Request;

                                                                                                                                                                                                                call signature

                                                                                                                                                                                                                (url: string | URL, options?: OptionsInit): CancelableRequest | Request;

                                                                                                                                                                                                                  call signature

                                                                                                                                                                                                                  (options: OptionsInit): CancelableRequest | Request;

                                                                                                                                                                                                                    call signature

                                                                                                                                                                                                                    (url: undefined, options: undefined, defaults: Options):
                                                                                                                                                                                                                    | CancelableRequest
                                                                                                                                                                                                                    | Request;

                                                                                                                                                                                                                      call signature

                                                                                                                                                                                                                      (url: string | URL, options?: OptionsOfBufferResponseBody): CancelableRequest<
                                                                                                                                                                                                                      Response<Buffer>
                                                                                                                                                                                                                      >;

                                                                                                                                                                                                                        call signature

                                                                                                                                                                                                                        (
                                                                                                                                                                                                                        url: string | URL,
                                                                                                                                                                                                                        options?: OptionsOfUnknownResponseBody
                                                                                                                                                                                                                        ): CancelableRequest<Response>;

                                                                                                                                                                                                                          call signature

                                                                                                                                                                                                                          (options: OptionsOfTextResponseBody): CancelableRequest<Response<string>>;

                                                                                                                                                                                                                            call signature

                                                                                                                                                                                                                            <T>(options: OptionsOfJSONResponseBody): CancelableRequest<Response<T>>;

                                                                                                                                                                                                                              call signature

                                                                                                                                                                                                                              (options: OptionsOfBufferResponseBody): CancelableRequest<Response<Buffer>>;

                                                                                                                                                                                                                                call signature

                                                                                                                                                                                                                                (options: OptionsOfUnknownResponseBody): CancelableRequest<Response>;

                                                                                                                                                                                                                                  call signature

                                                                                                                                                                                                                                  (
                                                                                                                                                                                                                                  url: string | URL,
                                                                                                                                                                                                                                  options?: Merge<OptionsOfTextResponseBody, ResponseBodyOnly>
                                                                                                                                                                                                                                  ): CancelableRequest<string>;

                                                                                                                                                                                                                                    call signature

                                                                                                                                                                                                                                    <T>(
                                                                                                                                                                                                                                    url: string | URL,
                                                                                                                                                                                                                                    options?: Merge<OptionsOfJSONResponseBody, ResponseBodyOnly>
                                                                                                                                                                                                                                    ): CancelableRequest<T>;

                                                                                                                                                                                                                                      interface Hooks

                                                                                                                                                                                                                                      interface Hooks {}
                                                                                                                                                                                                                                      • All available hooks of Got.

                                                                                                                                                                                                                                      property afterResponse

                                                                                                                                                                                                                                      afterResponse: AfterResponseHook[];
                                                                                                                                                                                                                                      • Each function should return the response. This is especially useful when you want to refresh an access token.

                                                                                                                                                                                                                                        []

                                                                                                                                                                                                                                        *Note:** > - When using the Stream API, this hook is ignored.

                                                                                                                                                                                                                                        *Note:** > - Calling the retryWithMergedOptions function will trigger beforeRetry hooks. If the retry is successful, all remaining afterResponse hooks will be called. In case of an error, beforeRetry hooks will be called instead. Meanwhile the init, beforeRequest , beforeRedirect as well as already executed afterResponse hooks will be skipped.

                                                                                                                                                                                                                                        Example 1

                                                                                                                                                                                                                                        ``` import got from 'got';

                                                                                                                                                                                                                                        const instance = got.extend({ hooks: { afterResponse: [ (response, retryWithMergedOptions) => { // Unauthorized if (response.statusCode === 401) { // Refresh the access token const updatedOptions = { headers: { token: getNewToken() } };

                                                                                                                                                                                                                                        // Update the defaults instance.defaults.options.merge(updatedOptions);

                                                                                                                                                                                                                                        // Make a new retry return retryWithMergedOptions(updatedOptions); }

                                                                                                                                                                                                                                        // No changes otherwise return response; } ], beforeRetry: [ error => { // This will be called on retryWithMergedOptions(...) } ] }, mutableDefaults: true }); ```

                                                                                                                                                                                                                                      property beforeError

                                                                                                                                                                                                                                      beforeError: BeforeErrorHook[];
                                                                                                                                                                                                                                      • Called with a RequestError instance. The error is passed to the hook right before it's thrown.

                                                                                                                                                                                                                                        This is especially useful when you want to have more detailed errors.

                                                                                                                                                                                                                                        []

                                                                                                                                                                                                                                        ``` import got from 'got';

                                                                                                                                                                                                                                        await got('https://api.github.com/repos/sindresorhus/got/commits', { responseType: 'json', hooks: { beforeError: [ error => { const {response} = error; if (response && response.body) { error.name = 'GitHubError'; error.message = ${response.body.message} (${response.statusCode}); }

                                                                                                                                                                                                                                        return error; } ] } }); ```

                                                                                                                                                                                                                                      property beforeRedirect

                                                                                                                                                                                                                                      beforeRedirect: BeforeRedirectHook[];
                                                                                                                                                                                                                                      • The equivalent of beforeRequest but when redirecting.

                                                                                                                                                                                                                                        []

                                                                                                                                                                                                                                        *Tip:** > - This is especially useful when you want to avoid dead sites.

                                                                                                                                                                                                                                        Example 1

                                                                                                                                                                                                                                        ``` import got from 'got';

                                                                                                                                                                                                                                        const response = await got('https://example.com', { hooks: { beforeRedirect: [ (options, response) => { if (options.hostname === 'deadSite') { options.hostname = 'fallbackSite'; } } ] } }); ```

                                                                                                                                                                                                                                      property beforeRequest

                                                                                                                                                                                                                                      beforeRequest: BeforeRequestHook[];
                                                                                                                                                                                                                                      • Called right before making the request with options.createNativeRequestOptions().

                                                                                                                                                                                                                                        This hook is especially useful in conjunction with got.extend() when you want to sign your request.

                                                                                                                                                                                                                                        []

                                                                                                                                                                                                                                        *Note:** > - Got will make no further changes to the request before it is sent.

                                                                                                                                                                                                                                        *Note:** > - Changing options.json or options.form has no effect on the request. You should change options.body instead. If needed, update the options.headers accordingly.

                                                                                                                                                                                                                                        Example 1

                                                                                                                                                                                                                                        ``` import got from 'got';

                                                                                                                                                                                                                                        const response = await got.post( 'https://httpbin.org/anything', { json: {payload: 'old'}, hooks: { beforeRequest: [ options => { options.body = JSON.stringify({payload: 'new'}); options.headers['content-length'] = options.body.length.toString(); } ] } } ); ```

                                                                                                                                                                                                                                        *Tip:** > - You can indirectly override the request function by early returning a [ClientRequest-like](https://nodejs.org/api/http.html#http_class_http_clientrequest) instance or a [IncomingMessage-like](https://nodejs.org/api/http.html#http_class_http_incomingmessage) instance. This is very useful when creating a custom cache mechanism. > - [Read more about this tip](https://github.com/sindresorhus/got/blob/main/documentation/cache.md#advanced-caching-mechanisms).

                                                                                                                                                                                                                                      property beforeRetry

                                                                                                                                                                                                                                      beforeRetry: BeforeRetryHook[];
                                                                                                                                                                                                                                      • The equivalent of beforeError but when retrying. Additionally, there is a second argument retryCount, the current retry number.

                                                                                                                                                                                                                                        []

                                                                                                                                                                                                                                        *Note:** > - When using the Stream API, this hook is ignored.

                                                                                                                                                                                                                                        *Note:** > - When retrying, the beforeRequest hook is called afterwards.

                                                                                                                                                                                                                                        *Note:** > - If no retry occurs, the beforeError hook is called instead.

                                                                                                                                                                                                                                        This hook is especially useful when you want to retrieve the cause of a retry.

                                                                                                                                                                                                                                        Example 1

                                                                                                                                                                                                                                        ``` import got from 'got';

                                                                                                                                                                                                                                        await got('https://httpbin.org/status/500', { hooks: { beforeRetry: [ (error, retryCount) => { console.log(Retrying [${retryCount}]: ${error.code}); // Retrying [1]: ERR_NON_2XX_3XX_RESPONSE } ] } }); ```

                                                                                                                                                                                                                                      property init

                                                                                                                                                                                                                                      init: InitHook[];
                                                                                                                                                                                                                                      • Called with the plain request options, right before their normalization.

                                                                                                                                                                                                                                        The second argument represents the current Options instance.

                                                                                                                                                                                                                                        []

                                                                                                                                                                                                                                        *Note:** > - This hook must be synchronous.

                                                                                                                                                                                                                                        *Note:** > - This is called every time options are merged.

                                                                                                                                                                                                                                        *Note:** > - The options object may not have the url property. To modify it, use a beforeRequest hook instead.

                                                                                                                                                                                                                                        *Note:** > - This hook is called when a new instance of Options is created. > - Do not confuse this with the creation of Request or got(…).

                                                                                                                                                                                                                                        *Note:** > - When using got(url) or got(url, undefined, defaults) this hook will **not** be called.

                                                                                                                                                                                                                                        This is especially useful in conjunction with got.extend() when the input needs custom handling.

                                                                                                                                                                                                                                        For example, this can be used to fix typos to migrate from older versions faster.

                                                                                                                                                                                                                                        Example 1

                                                                                                                                                                                                                                        ``` import got from 'got';

                                                                                                                                                                                                                                        const instance = got.extend({ hooks: { init: [ plain => { if ('followRedirects' in plain) { plain.followRedirect = plain.followRedirects; delete plain.followRedirects; } } ] } });

                                                                                                                                                                                                                                        // Normally, the following would throw: const response = await instance( 'https://example.com', { followRedirects: true } );

                                                                                                                                                                                                                                        // There is no option named followRedirects, but we correct it in an init hook. ```

                                                                                                                                                                                                                                        Or you can create your own option and store it in a context:

                                                                                                                                                                                                                                        ``` import got from 'got';

                                                                                                                                                                                                                                        const instance = got.extend({ hooks: { init: [ (plain, options) => { if ('secret' in plain) { options.context.secret = plain.secret; delete plain.secret; } } ], beforeRequest: [ options => { options.headers.secret = options.context.secret; } ] } });

                                                                                                                                                                                                                                        const {headers} = await instance( 'https://httpbin.org/anything', { secret: 'passphrase' } ).json();

                                                                                                                                                                                                                                        console.log(headers.Secret); //=> 'passphrase' ```

                                                                                                                                                                                                                                      interface HttpsOptions

                                                                                                                                                                                                                                      interface HttpsOptions {}

                                                                                                                                                                                                                                        property alpnProtocols

                                                                                                                                                                                                                                        alpnProtocols?: string[];

                                                                                                                                                                                                                                          property certificate

                                                                                                                                                                                                                                          certificate?: SecureContextOptions['cert'];
                                                                                                                                                                                                                                          • [Certificate chains](https://en.wikipedia.org/wiki/X.509#Certificate_chains_and_cross-certification) in [PEM](https://en.wikipedia.org/wiki/Privacy-Enhanced_Mail) format.

                                                                                                                                                                                                                                            One cert chain should be provided per private key (options.https.key).

                                                                                                                                                                                                                                            When providing multiple cert chains, they do not have to be in the same order as their private keys in options.https.key.

                                                                                                                                                                                                                                            If the intermediate certificates are not provided, the peer will not be able to validate the certificate, and the handshake will fail.

                                                                                                                                                                                                                                          property certificateAuthority

                                                                                                                                                                                                                                          certificateAuthority?: SecureContextOptions['ca'];
                                                                                                                                                                                                                                          • Override the default Certificate Authorities ([from Mozilla](https://ccadb-public.secure.force.com/mozilla/IncludedCACertificateReport)).

                                                                                                                                                                                                                                            Example 1

                                                                                                                                                                                                                                            ``` // Single Certificate Authority await got('https://example.com', { https: { certificateAuthority: fs.readFileSync('./my_ca.pem') } }); ```

                                                                                                                                                                                                                                          property certificateRevocationLists

                                                                                                                                                                                                                                          certificateRevocationLists?: SecureContextOptions['crl'];

                                                                                                                                                                                                                                            property checkServerIdentity

                                                                                                                                                                                                                                            checkServerIdentity?: CheckServerIdentityFunction;

                                                                                                                                                                                                                                              property ciphers

                                                                                                                                                                                                                                              ciphers?: SecureContextOptions['ciphers'];

                                                                                                                                                                                                                                                property dhparam

                                                                                                                                                                                                                                                dhparam?: SecureContextOptions['dhparam'];

                                                                                                                                                                                                                                                  property ecdhCurve

                                                                                                                                                                                                                                                  ecdhCurve?: SecureContextOptions['ecdhCurve'];

                                                                                                                                                                                                                                                    property honorCipherOrder

                                                                                                                                                                                                                                                    honorCipherOrder?: SecureContextOptions['honorCipherOrder'];

                                                                                                                                                                                                                                                      property key

                                                                                                                                                                                                                                                      key?: SecureContextOptions['key'];
                                                                                                                                                                                                                                                      • Private keys in [PEM](https://en.wikipedia.org/wiki/Privacy-Enhanced_Mail) format.

                                                                                                                                                                                                                                                        [PEM](https://en.wikipedia.org/wiki/Privacy-Enhanced_Mail) allows the option of private keys being encrypted. Encrypted keys will be decrypted with options.https.passphrase.

                                                                                                                                                                                                                                                        Multiple keys with different passphrases can be provided as an array of {pem: <string | Buffer>, passphrase: <string>}

                                                                                                                                                                                                                                                      property maxVersion

                                                                                                                                                                                                                                                      maxVersion?: SecureContextOptions['maxVersion'];

                                                                                                                                                                                                                                                        property minVersion

                                                                                                                                                                                                                                                        minVersion?: SecureContextOptions['minVersion'];

                                                                                                                                                                                                                                                          property passphrase

                                                                                                                                                                                                                                                          passphrase?: SecureContextOptions['passphrase'];
                                                                                                                                                                                                                                                          • The passphrase to decrypt the options.https.key (if different keys have different passphrases refer to options.https.key documentation).

                                                                                                                                                                                                                                                          property pfx

                                                                                                                                                                                                                                                          pfx?: PfxType;

                                                                                                                                                                                                                                                            property rejectUnauthorized

                                                                                                                                                                                                                                                            rejectUnauthorized?: NativeRequestOptions['rejectUnauthorized'];

                                                                                                                                                                                                                                                              property signatureAlgorithms

                                                                                                                                                                                                                                                              signatureAlgorithms?: SecureContextOptions['sigalgs'];

                                                                                                                                                                                                                                                                property tlsSessionLifetime

                                                                                                                                                                                                                                                                tlsSessionLifetime?: SecureContextOptions['sessionTimeout'];

                                                                                                                                                                                                                                                                  interface InstanceDefaults

                                                                                                                                                                                                                                                                  interface InstanceDefaults {}
                                                                                                                                                                                                                                                                  • Defaults for each Got instance.

                                                                                                                                                                                                                                                                  property handlers

                                                                                                                                                                                                                                                                  handlers: HandlerFunction[];
                                                                                                                                                                                                                                                                  • An array of functions. You execute them directly by calling got(). They are some sort of "global hooks" - these functions are called first. The last handler (*it's hidden*) is either asPromise or asStream, depending on the options.isStream property.

                                                                                                                                                                                                                                                                    []

                                                                                                                                                                                                                                                                  property mutableDefaults

                                                                                                                                                                                                                                                                  mutableDefaults: boolean;
                                                                                                                                                                                                                                                                  • A read-only boolean describing whether the defaults are mutable or not. If set to true, you can update headers over time, for example, update an access token when it expires.

                                                                                                                                                                                                                                                                    false

                                                                                                                                                                                                                                                                  property options

                                                                                                                                                                                                                                                                  options: Options;
                                                                                                                                                                                                                                                                  • An object containing the default options of Got.

                                                                                                                                                                                                                                                                  interface PaginateData

                                                                                                                                                                                                                                                                  interface PaginateData<BodyType, ElementType> {}

                                                                                                                                                                                                                                                                    property allItems

                                                                                                                                                                                                                                                                    allItems: ElementType[];

                                                                                                                                                                                                                                                                      property currentItems

                                                                                                                                                                                                                                                                      currentItems: ElementType[];

                                                                                                                                                                                                                                                                        property response

                                                                                                                                                                                                                                                                        response: Response<BodyType>;

                                                                                                                                                                                                                                                                          interface PaginationOptions

                                                                                                                                                                                                                                                                          interface PaginationOptions<ElementType, BodyType> {}
                                                                                                                                                                                                                                                                          • All options accepted by got.paginate().

                                                                                                                                                                                                                                                                          property backoff

                                                                                                                                                                                                                                                                          backoff?: number;
                                                                                                                                                                                                                                                                          • Milliseconds to wait before the next request is triggered.

                                                                                                                                                                                                                                                                            0

                                                                                                                                                                                                                                                                          property countLimit

                                                                                                                                                                                                                                                                          countLimit?: number;
                                                                                                                                                                                                                                                                          • The maximum amount of items that should be emitted.

                                                                                                                                                                                                                                                                            Infinity

                                                                                                                                                                                                                                                                          property filter

                                                                                                                                                                                                                                                                          filter?: (data: FilterData<ElementType>) => boolean;
                                                                                                                                                                                                                                                                          • Checks whether the item should be emitted or not.

                                                                                                                                                                                                                                                                            ({item, currentItems, allItems}) => true

                                                                                                                                                                                                                                                                          property paginate

                                                                                                                                                                                                                                                                          paginate?: (data: PaginateData<BodyType, ElementType>) => OptionsInit | false;
                                                                                                                                                                                                                                                                          • The function takes an object with the following properties: - response - The current response object. - currentItems - Items from the current response. - allItems - An empty array, unless pagination.stackAllItems is set to true, in which case, it's an array of the emitted items.

                                                                                                                                                                                                                                                                            It should return an object representing Got options pointing to the next page. The options are merged automatically with the previous request, therefore the options returned pagination.paginate(...) must reflect changes only. If there are no more pages, false should be returned.

                                                                                                                                                                                                                                                                            Example 1

                                                                                                                                                                                                                                                                            ``` import got from 'got';

                                                                                                                                                                                                                                                                            const limit = 10;

                                                                                                                                                                                                                                                                            const items = got.paginate('https://example.com/items', { searchParams: { limit, offset: 0 }, pagination: { paginate: ({response, currentItems}) => { const previousSearchParams = response.request.options.searchParams; const previousOffset = previousSearchParams.get('offset');

                                                                                                                                                                                                                                                                            if (currentItems.length < limit) { return false; }

                                                                                                                                                                                                                                                                            return { searchParams: { ...previousSearchParams, offset: Number(previousOffset) + limit, } }; } } });

                                                                                                                                                                                                                                                                            console.log('Items from all pages:', items); ```

                                                                                                                                                                                                                                                                          property requestLimit

                                                                                                                                                                                                                                                                          requestLimit?: number;
                                                                                                                                                                                                                                                                          • The maximum amount of request that should be triggered. Retries on failure are not counted towards this limit.

                                                                                                                                                                                                                                                                            For example, it can be helpful during development to avoid an infinite number of requests.

                                                                                                                                                                                                                                                                            10000

                                                                                                                                                                                                                                                                          property shouldContinue

                                                                                                                                                                                                                                                                          shouldContinue?: (data: FilterData<ElementType>) => boolean;
                                                                                                                                                                                                                                                                          • Checks whether the pagination should continue.

                                                                                                                                                                                                                                                                            For example, if you need to stop **before** emitting an entry with some flag, you should use ({item}) => !item.flag.

                                                                                                                                                                                                                                                                            If you want to stop **after** emitting the entry, you should use ({item, allItems}) => allItems.some(item => item.flag) instead.

                                                                                                                                                                                                                                                                            ({item, currentItems, allItems}) => true

                                                                                                                                                                                                                                                                          property stackAllItems

                                                                                                                                                                                                                                                                          stackAllItems?: boolean;
                                                                                                                                                                                                                                                                          • Defines how the property allItems in pagination.paginate, pagination.filter and pagination.shouldContinue is managed.

                                                                                                                                                                                                                                                                            By default, the property allItems is always an empty array. This setting can be helpful to save on memory usage when working with a large dataset.

                                                                                                                                                                                                                                                                            When set to true, the property allItems is an array of the emitted items.

                                                                                                                                                                                                                                                                            false

                                                                                                                                                                                                                                                                          property transform

                                                                                                                                                                                                                                                                          transform?: (
                                                                                                                                                                                                                                                                          response: Response<BodyType>
                                                                                                                                                                                                                                                                          ) => Promise<ElementType[]> | ElementType[];
                                                                                                                                                                                                                                                                          • A function that transform [Response](#response) into an array of items. This is where you should do the parsing.

                                                                                                                                                                                                                                                                            response => JSON.parse(response.body)

                                                                                                                                                                                                                                                                          interface PlainResponse

                                                                                                                                                                                                                                                                          interface PlainResponse extends IncomingMessageWithTimings {}

                                                                                                                                                                                                                                                                            property body

                                                                                                                                                                                                                                                                            body?: unknown;
                                                                                                                                                                                                                                                                            • The result of the request.

                                                                                                                                                                                                                                                                            property ip

                                                                                                                                                                                                                                                                            ip?: string;
                                                                                                                                                                                                                                                                            • The remote IP address.

                                                                                                                                                                                                                                                                              This is hopefully a temporary limitation, see [lukechilds/cacheable-request#86](https://github.com/lukechilds/cacheable-request/issues/86).

                                                                                                                                                                                                                                                                              __Note__: Not available when the response is cached.

                                                                                                                                                                                                                                                                            property isFromCache

                                                                                                                                                                                                                                                                            isFromCache: boolean;
                                                                                                                                                                                                                                                                            • Whether the response was retrieved from the cache.

                                                                                                                                                                                                                                                                            property rawBody

                                                                                                                                                                                                                                                                            rawBody?: Buffer;
                                                                                                                                                                                                                                                                            • The raw result of the request.

                                                                                                                                                                                                                                                                            property redirectUrls

                                                                                                                                                                                                                                                                            redirectUrls: URL[];
                                                                                                                                                                                                                                                                            • The redirect URLs.

                                                                                                                                                                                                                                                                            property request

                                                                                                                                                                                                                                                                            request: Request;
                                                                                                                                                                                                                                                                            • - options - The Got options that were set on this request.

                                                                                                                                                                                                                                                                              __Note__: This is not a [http.ClientRequest](https://nodejs.org/api/http.html#http_class_http_clientrequest).

                                                                                                                                                                                                                                                                            property requestUrl

                                                                                                                                                                                                                                                                            requestUrl: URL;
                                                                                                                                                                                                                                                                            • The original request URL.

                                                                                                                                                                                                                                                                            property retryCount

                                                                                                                                                                                                                                                                            retryCount: number;
                                                                                                                                                                                                                                                                            • The number of times the request was retried.

                                                                                                                                                                                                                                                                            property statusCode

                                                                                                                                                                                                                                                                            statusCode: number;
                                                                                                                                                                                                                                                                            • The status code of the response.

                                                                                                                                                                                                                                                                            property timings

                                                                                                                                                                                                                                                                            timings: Timings;
                                                                                                                                                                                                                                                                            • The object contains the following properties:

                                                                                                                                                                                                                                                                              - start - Time when the request started. - socket - Time when a socket was assigned to the request. - lookup - Time when the DNS lookup finished. - connect - Time when the socket successfully connected. - secureConnect - Time when the socket securely connected. - upload - Time when the request finished uploading. - response - Time when the request fired response event. - end - Time when the response fired end event. - error - Time when the request fired error event. - abort - Time when the request fired abort event. - phases - wait - timings.socket - timings.start - dns - timings.lookup - timings.socket - tcp - timings.connect - timings.lookup - tls - timings.secureConnect - timings.connect - request - timings.upload - (timings.secureConnect || timings.connect) - firstByte - timings.response - timings.upload - download - timings.end - timings.response - total - (timings.end || timings.error || timings.abort) - timings.start

                                                                                                                                                                                                                                                                              If something has not been measured yet, it will be undefined.

                                                                                                                                                                                                                                                                              __Note__: The time is a number representing the milliseconds elapsed since the UNIX epoch.

                                                                                                                                                                                                                                                                            property url

                                                                                                                                                                                                                                                                            url: string;
                                                                                                                                                                                                                                                                            • The request URL or the final URL after redirects.

                                                                                                                                                                                                                                                                            interface Progress

                                                                                                                                                                                                                                                                            interface Progress {}

                                                                                                                                                                                                                                                                              property percent

                                                                                                                                                                                                                                                                              percent: number;

                                                                                                                                                                                                                                                                                property total

                                                                                                                                                                                                                                                                                total?: number;

                                                                                                                                                                                                                                                                                  property transferred

                                                                                                                                                                                                                                                                                  transferred: number;

                                                                                                                                                                                                                                                                                    interface PromiseCookieJar

                                                                                                                                                                                                                                                                                    interface PromiseCookieJar {}

                                                                                                                                                                                                                                                                                      property getCookieString

                                                                                                                                                                                                                                                                                      getCookieString: (url: string) => Promise<string>;

                                                                                                                                                                                                                                                                                        property setCookie

                                                                                                                                                                                                                                                                                        setCookie: (rawCookie: string, url: string) => Promise<unknown>;

                                                                                                                                                                                                                                                                                          interface RequestEvents

                                                                                                                                                                                                                                                                                          interface RequestEvents<T> {}

                                                                                                                                                                                                                                                                                            property on

                                                                                                                                                                                                                                                                                            on: GotEventFunction<T>;

                                                                                                                                                                                                                                                                                              property once

                                                                                                                                                                                                                                                                                              once: GotEventFunction<T>;

                                                                                                                                                                                                                                                                                                interface Response

                                                                                                                                                                                                                                                                                                interface Response<T = unknown> extends PlainResponse {}

                                                                                                                                                                                                                                                                                                  property body

                                                                                                                                                                                                                                                                                                  body: T;
                                                                                                                                                                                                                                                                                                  • The result of the request.

                                                                                                                                                                                                                                                                                                  property rawBody

                                                                                                                                                                                                                                                                                                  rawBody: Buffer;
                                                                                                                                                                                                                                                                                                  • The raw result of the request.

                                                                                                                                                                                                                                                                                                  interface RetryObject

                                                                                                                                                                                                                                                                                                  interface RetryObject {}

                                                                                                                                                                                                                                                                                                    property attemptCount

                                                                                                                                                                                                                                                                                                    attemptCount: number;

                                                                                                                                                                                                                                                                                                      property computedValue

                                                                                                                                                                                                                                                                                                      computedValue: number;

                                                                                                                                                                                                                                                                                                        property error

                                                                                                                                                                                                                                                                                                        error: RequestError;

                                                                                                                                                                                                                                                                                                          property retryAfter

                                                                                                                                                                                                                                                                                                          retryAfter?: number;

                                                                                                                                                                                                                                                                                                            property retryOptions

                                                                                                                                                                                                                                                                                                            retryOptions: RetryOptions;

                                                                                                                                                                                                                                                                                                              interface RetryOptions

                                                                                                                                                                                                                                                                                                              interface RetryOptions {}
                                                                                                                                                                                                                                                                                                              • An object representing limit, calculateDelay, methods, statusCodes, maxRetryAfter and errorCodes fields for maximum retry count, retry handler, allowed methods, allowed status codes, maximum [Retry-After](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After) time and allowed error codes.

                                                                                                                                                                                                                                                                                                                Delays between retries counts with function 1000 * Math.pow(2, retry) + Math.random() * 100, where retry is attempt number (starts from 1).

                                                                                                                                                                                                                                                                                                                The calculateDelay property is a function that receives an object with attemptCount, retryOptions, error and computedValue properties for current retry count, the retry options, error and default computed value. The function must return a delay in milliseconds (or a Promise resolving with it) (0 return value cancels retry).

                                                                                                                                                                                                                                                                                                                By default, it retries *only* on the specified methods, status codes, and on these network errors: - ETIMEDOUT: One of the [timeout](#timeout) limits were reached. - ECONNRESET: Connection was forcibly closed by a peer. - EADDRINUSE: Could not bind to any free port. - ECONNREFUSED: Connection was refused by the server. - EPIPE: The remote side of the stream being written has been closed. - ENOTFOUND: Couldn't resolve the hostname to an IP address. - ENETUNREACH: No internet connection. - EAI_AGAIN: DNS lookup timed out.

                                                                                                                                                                                                                                                                                                                __Note:__ Got does not retry on POST by default. __Note:__ If maxRetryAfter is set to undefined, it will use options.timeout. __Note:__ If [Retry-After](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After) header is greater than maxRetryAfter, it will cancel the request.

                                                                                                                                                                                                                                                                                                              property backoffLimit

                                                                                                                                                                                                                                                                                                              backoffLimit: number;

                                                                                                                                                                                                                                                                                                                property calculateDelay

                                                                                                                                                                                                                                                                                                                calculateDelay: RetryFunction;

                                                                                                                                                                                                                                                                                                                  property errorCodes

                                                                                                                                                                                                                                                                                                                  errorCodes: string[];

                                                                                                                                                                                                                                                                                                                    property limit

                                                                                                                                                                                                                                                                                                                    limit: number;

                                                                                                                                                                                                                                                                                                                      property maxRetryAfter

                                                                                                                                                                                                                                                                                                                      maxRetryAfter?: number;

                                                                                                                                                                                                                                                                                                                        property methods

                                                                                                                                                                                                                                                                                                                        methods: Method[];

                                                                                                                                                                                                                                                                                                                          property noise

                                                                                                                                                                                                                                                                                                                          noise: number;

                                                                                                                                                                                                                                                                                                                            property statusCodes

                                                                                                                                                                                                                                                                                                                            statusCodes: number[];

                                                                                                                                                                                                                                                                                                                              interface ToughCookieJar

                                                                                                                                                                                                                                                                                                                              interface ToughCookieJar {}

                                                                                                                                                                                                                                                                                                                                property getCookieString

                                                                                                                                                                                                                                                                                                                                getCookieString: ((
                                                                                                                                                                                                                                                                                                                                currentUrl: string,
                                                                                                                                                                                                                                                                                                                                options: Record<string, unknown>,
                                                                                                                                                                                                                                                                                                                                cb: (error: Error | null, cookies: string) => void
                                                                                                                                                                                                                                                                                                                                ) => void) &
                                                                                                                                                                                                                                                                                                                                ((
                                                                                                                                                                                                                                                                                                                                url: string,
                                                                                                                                                                                                                                                                                                                                callback: (error: Error | null, cookieHeader: string) => void
                                                                                                                                                                                                                                                                                                                                ) => void);

                                                                                                                                                                                                                                                                                                                                  property setCookie

                                                                                                                                                                                                                                                                                                                                  setCookie: ((
                                                                                                                                                                                                                                                                                                                                  cookieOrString: unknown,
                                                                                                                                                                                                                                                                                                                                  currentUrl: string,
                                                                                                                                                                                                                                                                                                                                  options: Record<string, unknown>,
                                                                                                                                                                                                                                                                                                                                  cb: (error: Error | null, cookie: unknown) => void
                                                                                                                                                                                                                                                                                                                                  ) => void) &
                                                                                                                                                                                                                                                                                                                                  ((
                                                                                                                                                                                                                                                                                                                                  rawCookie: string,
                                                                                                                                                                                                                                                                                                                                  url: string,
                                                                                                                                                                                                                                                                                                                                  callback: (error: Error | null, result: unknown) => void
                                                                                                                                                                                                                                                                                                                                  ) => void);

                                                                                                                                                                                                                                                                                                                                    Type Aliases

                                                                                                                                                                                                                                                                                                                                    type AfterResponseHook

                                                                                                                                                                                                                                                                                                                                    type AfterResponseHook<ResponseType = unknown> = (
                                                                                                                                                                                                                                                                                                                                    response: Response<ResponseType>,
                                                                                                                                                                                                                                                                                                                                    retryWithMergedOptions: (options: OptionsInit) => never
                                                                                                                                                                                                                                                                                                                                    ) => Promisable<Response | CancelableRequest<Response>>;

                                                                                                                                                                                                                                                                                                                                      type BeforeErrorHook

                                                                                                                                                                                                                                                                                                                                      type BeforeErrorHook = (error: RequestError) => Promisable<RequestError>;

                                                                                                                                                                                                                                                                                                                                        type BeforeRedirectHook

                                                                                                                                                                                                                                                                                                                                        type BeforeRedirectHook = (
                                                                                                                                                                                                                                                                                                                                        updatedOptions: Options,
                                                                                                                                                                                                                                                                                                                                        plainResponse: PlainResponse
                                                                                                                                                                                                                                                                                                                                        ) => Promisable<void>;

                                                                                                                                                                                                                                                                                                                                          type BeforeRequestHook

                                                                                                                                                                                                                                                                                                                                          type BeforeRequestHook = (
                                                                                                                                                                                                                                                                                                                                          options: Options
                                                                                                                                                                                                                                                                                                                                          ) => Promisable<void | Response | ResponseLike>;

                                                                                                                                                                                                                                                                                                                                            type BeforeRetryHook

                                                                                                                                                                                                                                                                                                                                            type BeforeRetryHook = (error: RequestError, retryCount: number) => Promisable<void>;

                                                                                                                                                                                                                                                                                                                                              type CacheableRequestFunction

                                                                                                                                                                                                                                                                                                                                              type CacheableRequestFunction = (
                                                                                                                                                                                                                                                                                                                                              options: string | URL | NativeRequestOptions,
                                                                                                                                                                                                                                                                                                                                              cb?: (response: ServerResponse | ResponseLike) => void
                                                                                                                                                                                                                                                                                                                                              ) => CacheableRequest.Emitter;

                                                                                                                                                                                                                                                                                                                                                type CheckServerIdentityFunction

                                                                                                                                                                                                                                                                                                                                                type CheckServerIdentityFunction = (
                                                                                                                                                                                                                                                                                                                                                hostname: string,
                                                                                                                                                                                                                                                                                                                                                certificate: DetailedPeerCertificate
                                                                                                                                                                                                                                                                                                                                                ) => NodeJS.ErrnoException | void;

                                                                                                                                                                                                                                                                                                                                                  type CreateConnectionFunction

                                                                                                                                                                                                                                                                                                                                                  type CreateConnectionFunction = (
                                                                                                                                                                                                                                                                                                                                                  options: NativeRequestOptions,
                                                                                                                                                                                                                                                                                                                                                  oncreate: (error: NodeJS.ErrnoException, socket: Socket) => void
                                                                                                                                                                                                                                                                                                                                                  ) => Socket;

                                                                                                                                                                                                                                                                                                                                                    type DnsLookupIpVersion

                                                                                                                                                                                                                                                                                                                                                    type DnsLookupIpVersion = undefined | 4 | 6;

                                                                                                                                                                                                                                                                                                                                                      type GotEventFunction

                                                                                                                                                                                                                                                                                                                                                      type GotEventFunction<T> =
                                                                                                                                                                                                                                                                                                                                                      /**
                                                                                                                                                                                                                                                                                                                                                      `request` event to get the request object of the request.
                                                                                                                                                                                                                                                                                                                                                      __Tip__: You can use `request` event to abort requests.
                                                                                                                                                                                                                                                                                                                                                      @example
                                                                                                                                                                                                                                                                                                                                                      ```
                                                                                                                                                                                                                                                                                                                                                      got.stream('https://github.com')
                                                                                                                                                                                                                                                                                                                                                      .on('request', request => setTimeout(() => request.destroy(), 50));
                                                                                                                                                                                                                                                                                                                                                      ```
                                                                                                                                                                                                                                                                                                                                                      */
                                                                                                                                                                                                                                                                                                                                                      ((name: 'request', listener: (request: ClientRequest) => void) => T) &
                                                                                                                                                                                                                                                                                                                                                      /**
                                                                                                                                                                                                                                                                                                                                                      The `response` event to get the response object of the final request.
                                                                                                                                                                                                                                                                                                                                                      */
                                                                                                                                                                                                                                                                                                                                                      (<R extends Response>(
                                                                                                                                                                                                                                                                                                                                                      name: 'response',
                                                                                                                                                                                                                                                                                                                                                      listener: (response: R) => void
                                                                                                                                                                                                                                                                                                                                                      ) => T) &
                                                                                                                                                                                                                                                                                                                                                      /**
                                                                                                                                                                                                                                                                                                                                                      The `redirect` event to get the response object of a redirect. The second argument is options for the next request to the redirect location.
                                                                                                                                                                                                                                                                                                                                                      */
                                                                                                                                                                                                                                                                                                                                                      (<R extends Response, N extends Options>(
                                                                                                                                                                                                                                                                                                                                                      name: 'redirect',
                                                                                                                                                                                                                                                                                                                                                      listener: (response: R, nextOptions: N) => void
                                                                                                                                                                                                                                                                                                                                                      ) => T) &
                                                                                                                                                                                                                                                                                                                                                      /**
                                                                                                                                                                                                                                                                                                                                                      Progress events for uploading (sending a request) and downloading (receiving a response).
                                                                                                                                                                                                                                                                                                                                                      The `progress` argument is an object like:
                                                                                                                                                                                                                                                                                                                                                      ```
                                                                                                                                                                                                                                                                                                                                                      {
                                                                                                                                                                                                                                                                                                                                                      percent: 0.1,
                                                                                                                                                                                                                                                                                                                                                      transferred: 1024,
                                                                                                                                                                                                                                                                                                                                                      total: 10240
                                                                                                                                                                                                                                                                                                                                                      }
                                                                                                                                                                                                                                                                                                                                                      ```
                                                                                                                                                                                                                                                                                                                                                      If the `content-length` header is missing, `total` will be `undefined`.
                                                                                                                                                                                                                                                                                                                                                      @example
                                                                                                                                                                                                                                                                                                                                                      ```
                                                                                                                                                                                                                                                                                                                                                      const response = await got('https://sindresorhus.com')
                                                                                                                                                                                                                                                                                                                                                      .on('downloadProgress', progress => {
                                                                                                                                                                                                                                                                                                                                                      // Report download progress
                                                                                                                                                                                                                                                                                                                                                      })
                                                                                                                                                                                                                                                                                                                                                      .on('uploadProgress', progress => {
                                                                                                                                                                                                                                                                                                                                                      // Report upload progress
                                                                                                                                                                                                                                                                                                                                                      });
                                                                                                                                                                                                                                                                                                                                                      console.log(response);
                                                                                                                                                                                                                                                                                                                                                      ```
                                                                                                                                                                                                                                                                                                                                                      */
                                                                                                                                                                                                                                                                                                                                                      ((
                                                                                                                                                                                                                                                                                                                                                      name: 'uploadProgress' | 'downloadProgress',
                                                                                                                                                                                                                                                                                                                                                      listener: (progress: Progress) => void
                                                                                                                                                                                                                                                                                                                                                      ) => T) &
                                                                                                                                                                                                                                                                                                                                                      /**
                                                                                                                                                                                                                                                                                                                                                      To enable retrying on a Got stream, it is required to have a `retry` handler attached.
                                                                                                                                                                                                                                                                                                                                                      When this event is emitted, you should reset the stream you were writing to and prepare the body again.
                                                                                                                                                                                                                                                                                                                                                      See `got.options.retry` for more information.
                                                                                                                                                                                                                                                                                                                                                      */
                                                                                                                                                                                                                                                                                                                                                      ((
                                                                                                                                                                                                                                                                                                                                                      name: 'retry',
                                                                                                                                                                                                                                                                                                                                                      listener: (retryCount: number, error: RequestError) => void
                                                                                                                                                                                                                                                                                                                                                      ) => T);

                                                                                                                                                                                                                                                                                                                                                        type GotReturn

                                                                                                                                                                                                                                                                                                                                                        type GotReturn = Request | CancelableRequest;
                                                                                                                                                                                                                                                                                                                                                        • A Request object returned by calling Got, or any of the Got HTTP alias request functions.

                                                                                                                                                                                                                                                                                                                                                        type GotStream

                                                                                                                                                                                                                                                                                                                                                        type GotStream = GotStreamFunction & Record<HTTPAlias, GotStreamFunction>;
                                                                                                                                                                                                                                                                                                                                                        • An instance of got.stream().

                                                                                                                                                                                                                                                                                                                                                        type HandlerFunction

                                                                                                                                                                                                                                                                                                                                                        type HandlerFunction = <T extends GotReturn>(
                                                                                                                                                                                                                                                                                                                                                        options: Options,
                                                                                                                                                                                                                                                                                                                                                        next: (options: Options) => T
                                                                                                                                                                                                                                                                                                                                                        ) => T | Promise<T>;
                                                                                                                                                                                                                                                                                                                                                        • A function to handle options and returns a Request object. It acts sort of like a "global hook", and will be called before any actual request is made.

                                                                                                                                                                                                                                                                                                                                                        type Headers

                                                                                                                                                                                                                                                                                                                                                        type Headers = Record<string, string | string[] | undefined>;

                                                                                                                                                                                                                                                                                                                                                          type HTTPAlias

                                                                                                                                                                                                                                                                                                                                                          type HTTPAlias = 'get' | 'post' | 'put' | 'patch' | 'head' | 'delete';
                                                                                                                                                                                                                                                                                                                                                          • All available HTTP request methods provided by Got.

                                                                                                                                                                                                                                                                                                                                                          type InitHook

                                                                                                                                                                                                                                                                                                                                                          type InitHook = (init: OptionsInit, self: Options) => void;

                                                                                                                                                                                                                                                                                                                                                            type InternalsType

                                                                                                                                                                                                                                                                                                                                                            type InternalsType = Except<Options, OptionsToSkip>;

                                                                                                                                                                                                                                                                                                                                                              type Method

                                                                                                                                                                                                                                                                                                                                                              type Method =
                                                                                                                                                                                                                                                                                                                                                              | 'GET'
                                                                                                                                                                                                                                                                                                                                                              | 'POST'
                                                                                                                                                                                                                                                                                                                                                              | 'PUT'
                                                                                                                                                                                                                                                                                                                                                              | 'PATCH'
                                                                                                                                                                                                                                                                                                                                                              | 'HEAD'
                                                                                                                                                                                                                                                                                                                                                              | 'DELETE'
                                                                                                                                                                                                                                                                                                                                                              | 'OPTIONS'
                                                                                                                                                                                                                                                                                                                                                              | 'TRACE'
                                                                                                                                                                                                                                                                                                                                                              | 'get'
                                                                                                                                                                                                                                                                                                                                                              | 'post'
                                                                                                                                                                                                                                                                                                                                                              | 'put'
                                                                                                                                                                                                                                                                                                                                                              | 'patch'
                                                                                                                                                                                                                                                                                                                                                              | 'head'
                                                                                                                                                                                                                                                                                                                                                              | 'delete'
                                                                                                                                                                                                                                                                                                                                                              | 'options'
                                                                                                                                                                                                                                                                                                                                                              | 'trace';
                                                                                                                                                                                                                                                                                                                                                              • All available HTTP request methods provided by Got.

                                                                                                                                                                                                                                                                                                                                                              type NativeRequestOptions

                                                                                                                                                                                                                                                                                                                                                              type NativeRequestOptions = HttpsRequestOptions &
                                                                                                                                                                                                                                                                                                                                                              CacheOptions & {
                                                                                                                                                                                                                                                                                                                                                              checkServerIdentity?: CheckServerIdentityFunction;
                                                                                                                                                                                                                                                                                                                                                              };

                                                                                                                                                                                                                                                                                                                                                                type OptionsError

                                                                                                                                                                                                                                                                                                                                                                type OptionsError = NodeJS.ErrnoException & {
                                                                                                                                                                                                                                                                                                                                                                options?: Options;
                                                                                                                                                                                                                                                                                                                                                                };

                                                                                                                                                                                                                                                                                                                                                                  type OptionsInit

                                                                                                                                                                                                                                                                                                                                                                  type OptionsInit = Except<Partial<InternalsType>, 'hooks' | 'retry'> & {
                                                                                                                                                                                                                                                                                                                                                                  hooks?: Partial<Hooks>;
                                                                                                                                                                                                                                                                                                                                                                  retry?: Partial<RetryOptions>;
                                                                                                                                                                                                                                                                                                                                                                  };

                                                                                                                                                                                                                                                                                                                                                                    type OptionsOfBufferResponseBody

                                                                                                                                                                                                                                                                                                                                                                    type OptionsOfBufferResponseBody = Merge<
                                                                                                                                                                                                                                                                                                                                                                    OptionsInit,
                                                                                                                                                                                                                                                                                                                                                                    {
                                                                                                                                                                                                                                                                                                                                                                    isStream?: false;
                                                                                                                                                                                                                                                                                                                                                                    resolveBodyOnly?: false;
                                                                                                                                                                                                                                                                                                                                                                    responseType: 'buffer';
                                                                                                                                                                                                                                                                                                                                                                    }
                                                                                                                                                                                                                                                                                                                                                                    >;

                                                                                                                                                                                                                                                                                                                                                                      type OptionsOfJSONResponseBody

                                                                                                                                                                                                                                                                                                                                                                      type OptionsOfJSONResponseBody = Merge<
                                                                                                                                                                                                                                                                                                                                                                      OptionsInit,
                                                                                                                                                                                                                                                                                                                                                                      {
                                                                                                                                                                                                                                                                                                                                                                      isStream?: false;
                                                                                                                                                                                                                                                                                                                                                                      resolveBodyOnly?: false;
                                                                                                                                                                                                                                                                                                                                                                      responseType?: 'json';
                                                                                                                                                                                                                                                                                                                                                                      }
                                                                                                                                                                                                                                                                                                                                                                      >;

                                                                                                                                                                                                                                                                                                                                                                        type OptionsOfTextResponseBody

                                                                                                                                                                                                                                                                                                                                                                        type OptionsOfTextResponseBody = Merge<
                                                                                                                                                                                                                                                                                                                                                                        OptionsInit,
                                                                                                                                                                                                                                                                                                                                                                        {
                                                                                                                                                                                                                                                                                                                                                                        isStream?: false;
                                                                                                                                                                                                                                                                                                                                                                        resolveBodyOnly?: false;
                                                                                                                                                                                                                                                                                                                                                                        responseType?: 'text';
                                                                                                                                                                                                                                                                                                                                                                        }
                                                                                                                                                                                                                                                                                                                                                                        >;

                                                                                                                                                                                                                                                                                                                                                                          type OptionsOfUnknownResponseBody

                                                                                                                                                                                                                                                                                                                                                                          type OptionsOfUnknownResponseBody = Merge<
                                                                                                                                                                                                                                                                                                                                                                          OptionsInit,
                                                                                                                                                                                                                                                                                                                                                                          {
                                                                                                                                                                                                                                                                                                                                                                          isStream?: false;
                                                                                                                                                                                                                                                                                                                                                                          resolveBodyOnly?: false;
                                                                                                                                                                                                                                                                                                                                                                          }
                                                                                                                                                                                                                                                                                                                                                                          >;

                                                                                                                                                                                                                                                                                                                                                                            type OptionsWithPagination

                                                                                                                                                                                                                                                                                                                                                                            type OptionsWithPagination<T = unknown, R = unknown> = Merge<
                                                                                                                                                                                                                                                                                                                                                                            OptionsInit,
                                                                                                                                                                                                                                                                                                                                                                            {
                                                                                                                                                                                                                                                                                                                                                                            pagination?: PaginationOptions<T, R>;
                                                                                                                                                                                                                                                                                                                                                                            }
                                                                                                                                                                                                                                                                                                                                                                            >;

                                                                                                                                                                                                                                                                                                                                                                              type ParseJsonFunction

                                                                                                                                                                                                                                                                                                                                                                              type ParseJsonFunction = (text: string) => unknown;

                                                                                                                                                                                                                                                                                                                                                                                type RequestFunction

                                                                                                                                                                                                                                                                                                                                                                                type RequestFunction = (
                                                                                                                                                                                                                                                                                                                                                                                url: URL,
                                                                                                                                                                                                                                                                                                                                                                                options: NativeRequestOptions,
                                                                                                                                                                                                                                                                                                                                                                                callback?: (response: AcceptableResponse) => void
                                                                                                                                                                                                                                                                                                                                                                                ) => AcceptableRequestResult;

                                                                                                                                                                                                                                                                                                                                                                                  type ResponseType

                                                                                                                                                                                                                                                                                                                                                                                  type ResponseType = 'json' | 'buffer' | 'text';
                                                                                                                                                                                                                                                                                                                                                                                  • All parsing methods supported by Got.

                                                                                                                                                                                                                                                                                                                                                                                  type RetryFunction

                                                                                                                                                                                                                                                                                                                                                                                  type RetryFunction = (retryObject: RetryObject) => Promisable<number>;

                                                                                                                                                                                                                                                                                                                                                                                    type SearchParameters

                                                                                                                                                                                                                                                                                                                                                                                    type SearchParameters = Record<string, string | number | boolean | null | undefined>;

                                                                                                                                                                                                                                                                                                                                                                                      type StreamOptions

                                                                                                                                                                                                                                                                                                                                                                                      type StreamOptions = Merge<
                                                                                                                                                                                                                                                                                                                                                                                      OptionsInit,
                                                                                                                                                                                                                                                                                                                                                                                      {
                                                                                                                                                                                                                                                                                                                                                                                      isStream?: true;
                                                                                                                                                                                                                                                                                                                                                                                      }
                                                                                                                                                                                                                                                                                                                                                                                      >;

                                                                                                                                                                                                                                                                                                                                                                                        type StrictOptions

                                                                                                                                                                                                                                                                                                                                                                                        type StrictOptions = Except<
                                                                                                                                                                                                                                                                                                                                                                                        OptionsInit,
                                                                                                                                                                                                                                                                                                                                                                                        'isStream' | 'responseType' | 'resolveBodyOnly'
                                                                                                                                                                                                                                                                                                                                                                                        >;

                                                                                                                                                                                                                                                                                                                                                                                          type StringifyJsonFunction

                                                                                                                                                                                                                                                                                                                                                                                          type StringifyJsonFunction = (object: unknown) => string;

                                                                                                                                                                                                                                                                                                                                                                                            Package Files (11)

                                                                                                                                                                                                                                                                                                                                                                                            Dependencies (13)

                                                                                                                                                                                                                                                                                                                                                                                            Dev Dependencies (43)

                                                                                                                                                                                                                                                                                                                                                                                            Peer Dependencies (0)

                                                                                                                                                                                                                                                                                                                                                                                            No peer dependencies.

                                                                                                                                                                                                                                                                                                                                                                                            Badge

                                                                                                                                                                                                                                                                                                                                                                                            To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                                                                                                                                                                                                                                                                                                                                                                                            You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/got.

                                                                                                                                                                                                                                                                                                                                                                                            • Markdown
                                                                                                                                                                                                                                                                                                                                                                                              [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/got)
                                                                                                                                                                                                                                                                                                                                                                                            • HTML
                                                                                                                                                                                                                                                                                                                                                                                              <a href="https://www.jsdocs.io/package/got"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>