API Routes

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

We believe API tools should be developed independently of the frontend framework.

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 Guides > RPC.

That said, creating API routes can make sense:

  • For specific needs where Telefunc doesn't fit, most notably file upload.
  • If you only need a handful of endpoints, creating a couple of API routes can be simpler than using Telefunc and thus adding yet another tool to your stack.

To create API routes, we recommend to simply use your server (such as Express.js or Hono) to create new HTTP GET/POST endpoints.

Make sure Vike's middleware is your last middleware. (Otherwise Vike's middleware, being a catch-all middleware, overrides your API routes.)

You may need to manually restart your server for changes to take effect, see #562.

See also