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

# Next.js

> Integration in Next.js routes and components

## API Route with Tryo

```ts theme={null}
import type { NextRequest } from "next/server";
import { NextResponse } from "next/server";
import { run } from "tryo";

export async function GET(_req: NextRequest) {
  const r = await run(
    () => fetch("https://example.com").then((x) => x.text()),
    {
      retries: 2,
      timeout: 1000,
    }
  );
  if (!r.ok)
    return NextResponse.json(
      { error: r.error },
      { status: r.error.status || 500 }
    );
  return NextResponse.json({ data: r.data });
}
```

## Server Component with Cancellation

```tsx theme={null}
import { run } from "tryo";

export default async function Page() {
  const r = await run(() => fetch("https://example.com").then((x) => x.json()));
  if (!r.ok) return <div>Error</div>;
  return <pre>{JSON.stringify(r.data, null, 2)}</pre>;
}
```
