# JavaScript quick start

Install Ky and make a JSON request with the default client.

Ky is a Fetch-based HTTP client with a simpler request and response interface. Use the [`ky`](https://bench-ky-56.atloria.app/p/bench-ky-56-cVfxjVA4Qg/developer/ky#default) default export with Fetch-compatible inputs and options; its response provides direct body shortcuts such as `.json()`.

## Prerequisites

- npm.
- A JavaScript or TypeScript project that can use ES modules.

Ky targets modern browsers, Node.js, Bun, and Deno.

## 1. Install Ky

Run this command in your project:

```bash
npm install ky
```

The command adds Ky to the project.

## Handle an HTTP failure

Non-2xx responses throw an [`HTTPError`](https://bench-ky-56.atloria.app/p/bench-ky-56-cVfxjVA4Qg/developer/ky-httperror#httperror) when HTTP errors are enabled. Use the [`isHTTPError`](https://bench-ky-56.atloria.app/p/bench-ky-56-cVfxjVA4Qg/developer/ky#ishttperror) type guard when the caller needs to inspect the status:

```ts title="src/load-user.ts"
import ky, {isHTTPError} from 'ky';

const main = async (): Promise<void> => {
	try {
		const user = await ky.get('https://jsonplaceholder.typicode.com/users/1').json();
		console.log(user);
	} catch (error) {
		if (isHTTPError(error)) {
			console.error(`Request failed with status ${error.response.status}`);
		} else {
			throw error;
		}
	}
};

void main();
```

The successful path receives parsed JSON. The failure path receives an `HTTPError` with the response status; network failures do not have a response because no response was received.

## What you have now

Your project can install Ky, send a request with the default client, and receive parsed JSON through `.json()`. For the request model and response shortcuts, continue to [Requests and responses](https://bench-ky-56.atloria.app/p/bench-ky-56-cVfxjVA4Qg/developer/requests-and-responses). To reuse URL and request defaults, see [Instances and defaults](https://bench-ky-56.atloria.app/p/bench-ky-56-cVfxjVA4Qg/developer/instances-and-defaults).
