H
Hono4w ago
Ayoub

Extract routes from hono definition

Hi everyone, i want to extract all the routes from hono definition for example :
export const app = new Hono<Env>()
.route('/transactions', transactionsRoute);
export const app = new Hono<Env>()
.route('/transactions', transactionsRoute);
How is it possible ?
I want to make a function that take a typesafe parameter that will be the route
const fn = (route: AnyPossibleRoute) => {}
const fn = (route: AnyPossibleRoute) => {}
and when i call the function fn, there will be autocompletion and i can have these possible options : /api/transactions /api/transactions/all /api/transactions/:id etc ... I'm fighting with ExtractSchema utility type but I don't achive my goal Thanks.
5 Replies
ambergristle
ambergristle4w ago
have you tried the Hono RPC client? sounds like that's what you want
Ayoub
AyoubOP4w ago
no I already use the RPC client for my frontend but what I want now is a specific use case in my backend but I found the solution :
type Routes = ExtractSchema<typeof app>;

const fn = (route: keyof Routes) => {};
type Routes = ExtractSchema<typeof app>;

const fn = (route: keyof Routes) => {};
ambergristle
ambergristle4w ago
ah gotcha out of curiosity, what are you using this for?
Ayoub
AyoubOP4w ago
for caching and manually invalidate cache http responses
ambergristle
ambergristle4w ago
sick

Did you find this page helpful?