Using the RPC server in react client code? #1220
Unanswered
stephencweiss
asked this question in
Q&A
Replies: 2 comments 1 reply
-
|
Hi @stephencweiss, To infer the path in the client correctly, we need to specify the base path for export const signinAPI = new Hono().basePath('/api/signin')
Then you can directly add the route to const app = new Hono()
app.route('/', signinAPI)However, if you do this, you won't be able to achieve your desired grouping: const app = new Hono().basePath('/api')
app.route('/signin', signinAPI)This is a technical issue. So, I recommend two patterns: 1. Specify const signinAPI = new Hono().basePath('/api/signin')
///
const client = hc<SigninAPI>()
///
const app = new Hono()
app.route('/', signinAPI)2. Specify base path in the client export const signinAPI = new Hono()
///
const client = hc<SigninAPI>('http://localhost:8000/api/signin')
///
const api = new Hono().basePath('/api')
api.route('/signin', signinAPI) |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
thanks @yusukebe! I will test this out. To be clear, the two pattern are distinct options. You wouldn't do both (as that doesn't make sense), right? |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm trying to use the pattern described in the docs here.
I did see this conversation, which if I'm reading correctly suggests that the
hc.clientis not particularly compatible with this pattern? is that right?The issues I'm currently facing:
This works... except that the server's
baseUrlis hard coded.For the server code, I've done the following:
Again, this works, but I found that if my
basePathwas not the full/api/signinthen the client didn't detect the path correctly from the Hono server.I think this is because I defined the type in the client as
SigninAPI-- where the client only understands this portion of the server. Is that right?My server is basically:
Where
api(and the associated typeAPI) s:I'm using Deno, though I don't think that actually makes a difference.
Any advice?
Specifically:
Update:
Initially I thought I'd solved the routing/discovery, but realized only later that the client was broken. I'm still at a loss here.
Beta Was this translation helpful? Give feedback.
All reactions