How to use custom fetch method for Hono client?
I have a noob question. I used to use the
axios
library and want a similar experience with the Hono client, such as shorter syntax, automatic JSON transformation and interceptors. Some suggest using ky
instead of axios
, but I don't know how to integrate it. The documentation (https://hono.dev/docs/guides/rpc#custom-fetch-method) is unclear to me. Could I get any guidance or example code?RPC - Hono
Ultrafast web framework for Cloudflare Workers, Fastly Compute, Deno, Bun, Vercel, Node.js, and others. Fast, but not only fast.
5 Replies
Hi @lessquo,
So the custom fetch method is for frameworks or runtimes that provide their own version of fetch. Cloudflare does this, so does SvelteKit. For something like axios or ky I don't believe you could integrate into it, nor would you need to. With the Hono Client you can make request simply. Once you set up the client, you call the route and the then method. No need to pass a url. And sending data is very simple as well.
Got it! Well, short syntax is not really important. But I really want the interceptors feature.
This is what I usually do with axios:
and here's my Hono client:
As you can see, Hono client can replace
axios
for the baseURL
and headers
, but not for the auto refetch and error handling. So, no way to achieve this currently?As far as I know, no I don't think there is any built in way to achieve this
Okay thanks! I’ll share if I find any solution or workaround
sorry for sending a message months later but did you ever solve this?