got

npm i got
import got from "got";
await got("https://example.com");
  • got.get
  • got.post
  • got.put
  • got.patch
  • got.delete
  • got.head

Don’t forget the await

Using response body

const response = await got("https://example.com");
const body = JSON.parse(response.body);

Search parameters

await got.get("https://example.com/foo", {
    searchParams: {
        sort: "ascending",
        items: 100,
        page: 2,
    },
});

Headers

await got("https://example.com", {
    headers: {
        "user-agent": "got v1.0.0",
    },
});

Extending

const api = got.extend({
    prefixUrl: "https://api.example.com",
});

await api.get("/foo");
await api.delete("/foo");

POST requests

await got.post("https://example.com", {
    json: {
        name: "John",
    },
    responseType: "json",
});