---
title: "Server code fetching its own API route (data/self-fetch)"
description: "A Server Component, Server Action or route handler that fetches this app's /api route makes an extra HTTP hop through the network and a second serverless invocation, and a relative URL fails on the server."
url: http://localhost:4173/rules/data/self-fetch
updated: 2026-11-11
---

# Server code fetching its own API route

> `data/self-fetch` is a vetd rule. It flags: Server code fetching its own API route. It runs on every `check`, together with the TypeScript check.

| Fact | Value |
| --- | --- |
| Rule id | `data/self-fetch` |
| Severity | warning |
| Group | Data fetching |
| Tags | performance, nextjs-16 |

## Why it matters

A Server Component, Server Action or route handler that fetches this app's /api route makes an extra HTTP hop through the network and a second serverless invocation, and a relative URL fails on the server.

## How to fix it

Import and call the function behind the route handler directly.

## Credit

Based on work by:

- [Vercel](https://vercel.com): The next-best-practices skill says to fetch data directly in Server Components instead of calling this app's own API route.

## References

- [next-best-practices: Data patterns](https://github.com/vercel-labs/next-skills/blob/dc1de9caf7612d73f56a8dec3cb1bd6c9ec096b9/skills/next-best-practices/data-patterns.md), Vercel (vercel-labs/next-skills)
- [Fetching Data](https://nextjs.org/docs/app/getting-started/fetching-data), Next.js
- [Route Handlers](https://nextjs.org/docs/app/getting-started/route-handlers), Next.js

## See it

Demos in the vetd Lab:

- [Fetch in Server Components](http://localhost:4173/lab/nextjs/fetch-in-server-components)

## Related rules

- [`next/fetch-in-effect`](http://localhost:4173/rules/next/fetch-in-effect.md)
- [`data/await-in-loop`](http://localhost:4173/rules/data/await-in-loop.md)

## Get this text from vetd

MCP: call `explain` with `{ "diagnosticId": "data/self-fetch" }`. CLI: `npx vetd explain data/self-fetch`.

---

[All 92 rules](http://localhost:4173/rules.md) · Previous: [`data/await-in-loop`](http://localhost:4173/rules/data/await-in-loop.md) · Next: [`data/client-fetch-waterfall`](http://localhost:4173/rules/data/client-fetch-waterfall.md)
