Skip to content

Is app.route supported for rpc? #2256

Answered by oskarkivra
oskarkivra asked this question in Q&A
Discussion options

You must be logged in to vote

That's a bummer.
If someone else are looking for alternatives I can share my findings:

  1. You can put you handlers in separated functions:
// books.ts
import type { Hono } from "hono";

export function addBookRoutes(app: Hono) {
  return app
    .post("api/book", (c) => c.json({ key: "123", title: "Hello" }, 201))
    .get("api/book", (c) => c.json({ key: "123", title: "Hello" }, 200));
}
// main.ts
import { Hono } from "hono";
import { hc } from "hono/client";
import { addBookRoutes } from "./books";
import { addMovieRoutes } from "./movies";

const app = new Hono();

addBookRoutes(app);
addMovieRoutes(app);
  
type App = ReturnType<typeof addInvoiceRoutes> & ReturnType<typeof addMovieRoutes

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by oskarkivra
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants