# Ky quick start

Install Ky, send a JSON request with a custom header, and read the JSON response body.

Ky is an HTTP client based on the Fetch API: pass a URL and options, then use a method shortcut and a body method to make a request and read its response.

## Prerequisites

Ky targets modern browsers, Node.js, Bun, and Deno. The package requires Node.js 22 or newer.

## Install

```bash
npm install ky
```

## Send a JSON request

1. Import the default [`ky`](https://bench-ky-6l.atloria.app/p/bench-ky-6l-QSDF7DxJ6h/developer/ky#default) export. Use `json` for the request body and `headers` for the custom request header. The `post()` shortcut sends a POST request; `json()` reads and parses the response body.

   ```ts
   import ky from 'ky';

   const main = async (): Promise<void> => {
     const result = await ky.post('https://httpbin.org/anything', {
       json: {name: 'Ada'},
       headers: {
         'x-client': 'ky-quick-start',
       },
     }).json();

     console.log(result);
   };

   void main();
   ```

   Inspect `result` in the console to see the parsed JSON response body. Its type is `unknown` by default; use a type argument when you know the response shape, or validate the response as described in [Send and read JSON](https://bench-ky-6l.atloria.app/p/bench-ky-6l-QSDF7DxJ6h/developer/send-and-read-json).

## What you have

Your code sends a POST request with a JSON body and the `x-client` header, then logs the parsed response body. Ky sets the JSON content type for the `json` option unless you provide a `Content-Type` header yourself. A non-2xx response throws an `HTTPError` by default, and `.json()` also throws if the response body is empty.

## Where to go next

- [Send and read JSON](https://bench-ky-6l.atloria.app/p/bench-ky-6l-QSDF7DxJ6h/developer/send-and-read-json) for response typing and JSON handling.
- [Add request headers](https://bench-ky-6l.atloria.app/p/bench-ky-6l-QSDF7DxJ6h/developer/add-request-headers) for reusable headers.
- [How Ky works](https://bench-ky-6l.atloria.app/p/bench-ky-6l-QSDF7DxJ6h/developer/how-ky-works) for the core concepts.
