Getting corrupted binary responses instead of JSON from Hono gateway service with axios
Hi everyone! I'm having an issue with my Hono-based API gateway that forwards requests to microservices. I’m receiving corrupted binary responses instead of the expected JSON when using axios or fetch from my React Native frontend.
Problem:
Requests return binary-like data instead of proper JSON:
Expected response:
Environment:
- Hono v4.8.4
- Cloudflare Workers
- Axios v1.10.0
- React Native with Expo
Setup:
My gateway service built with Hono forwards requests to the auth microservice, which returns proper JSON when called directly.
Gateway code:
What I've tried:
1. Different axios versions
2. Native fetch
3. Direct calls to the auth service (worked fine)
4. Adjusting Content-Type headers
5. Checking network response (shows corrupted data)
6. Added JSON parsing in interceptors
7. Verified auth service with curl
Key observations:
- Works fine when calling the auth service directly.
- The issue only occurs through the Hono gateway.
- Both axios and fetch result in the same corrupted response.
Could this be related to response compression, double JSON stringification, header forwarding, or a Cloudflare Workers behavior? Any suggestions would be appreciated!
2 Replies
if you're always returning json, why forward the response content type header at all?
^^
and why are you not using the ctx.json helper?
return ctx.json(response.data, response.status)