Blade automatically generates REST API routes at /api
for your triggers if you define the following in the file of your triggers:
export const exposed = true;
API routes should only be used if you need to interact with your app from a client that is not the browser. For example, if you are also building a native iOS app, you could send HTTP requests to the auto-generated REST API from there.
On the client side of the application you've built using Blade (within the browser), however, you should always make use of useMutation instead, which guarantees that all read queries on the page are revalidated upon a mutation, avoiding the need for custom client-side data state management.
In the rare case that you need to mount an API with a specific request signature to your Blade application, you can add a router.ts
file at the root of your application and place a Hono app inside of it, which will then be mounted by Blade:
import { Hono } from "hono";
const app = new Hono()
.post('/some-path', (c) => c.text('Testing'));
export default app;
However, note that paths mounted in this Hono app cannot interface with the rest of your Blade app in any way. They are only meant to be used in edge cases where you cannot rely on Blade's trigger feature. In other words, your Hono app and your Blade app are two different apps running on the same domain.