Edit this page

API Routes

By design Vike doesn't include built-in support for API routes.

We believe API tools should be developed independently of Vike.

See Guides > Data Fetching for a general introduction about fetching data with Vike.

We generally recommend using Telefunc (or another RPC tool) instead of API routes, see RPC.

That said, creating API routes can make sense:

  • For specific needs where Telefunc doesn't fit, such as file uploads or fine-grained HTTP cache control.
  • If you only need a handful of endpoints, creating a couple of API routes can be simpler than adding a new tool to your stack.

To achieve a similar DX as API routes, you can use a server like Express.js or Hono to create server routes that handle HTTP GET/POST endpoints.

Make sure Vike's middleware is your last middleware. (It's a catch-all middleware so it would override your API routes.)

If you don't use vike-server, then you may need to manually restart your server for changes to take effect.

See also