Nitro logoNitro

Server Fetch

Internal server-to-server requests without network overhead.
routes/index.ts
import { defineHandler } from "nitro/h3";
import { fetch } from "nitro";

export default defineHandler(() => fetch("/hello"));

When you need one route to call another, use Nitro's fetch function instead of the global fetch. It makes internal requests that stay in-process, avoiding network round-trips. The request never leaves the server.

Main Route

index.ts
import { defineHandler } from "nitro/h3";
import { fetch } from "nitro";

export default defineHandler(() => fetch("/hello"));

The index route imports fetch from nitro (not the global fetch) and calls the /hello route. This request is handled internally without going through the network stack.

Internal API Route

hello.ts
import { defineHandler } from "nitro/h3";

export default defineHandler(() => "Hello!");

A simple route that returns "Hello!". When the index route calls fetch("/hello"), this handler runs and its response is returned directly.

Learn More