> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/zhcndoc/bun/llms.txt
> Use this file to discover all available pages before exploring further.

# Send HTTP requests with fetch

> Make HTTP requests using the fetch API

Bun implements the standard `fetch()` API for HTTP requests.

## Basic GET Request

```typescript theme={null}
const response = await fetch("https://api.example.com/data");
const data = await response.json();
console.log(data);
```

## POST Request

```typescript theme={null}
const response = await fetch("https://api.example.com/users", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    name: "John Doe",
    email: "john@example.com",
  }),
});

const result = await response.json();
```

## Error Handling

```typescript theme={null}
try {
  const response = await fetch("https://api.example.com/data");
  
  if (!response.ok) {
    throw new Error(`HTTP error: ${response.status}`);
  }
  
  const data = await response.json();
} catch (error) {
  console.error("Fetch failed:", error);
}
```

## Timeout

```typescript theme={null}
const controller = new AbortController();
const timeout = setTimeout(() => controller.abort(), 5000);

try {
  const response = await fetch("https://api.example.com/data", {
    signal: controller.signal,
  });
  const data = await response.json();
} catch (error) {
  if (error.name === "AbortError") {
    console.log("Request timeout");
  }
} finally {
  clearTimeout(timeout);
}
```
