Nitro logoNitro

Server Fetch

Internal server-to-server requests without network overhead.

routes
hello.ts
index.ts
nitro.config.ts
package.json
tsconfig.json
vite.config.ts
import { defineHandler } from "nitro";
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

routes/index.ts
import { defineHandler } from "nitro";
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

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

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

Nitro logo

Nitro  Ship Full-stack Vite Apps.