H
Hono2mo ago
ggggggg

POST @hono/zod-validator seems to fail

I have a fairly minimal use-case, in which I'd like to validate that the json posted to an endpoint is correct ala zod. However, it bombs immediately with the following.
{"success":false,"error":{"issues":[{"code":"invalid_type","expected":"string","received":"undefined","path":["source"],"message":"Required"}],"name":"ZodError"}}
{"success":false,"error":{"issues":[{"code":"invalid_type","expected":"string","received":"undefined","path":["source"],"message":"Required"}],"name":"ZodError"}}
POST some json:
curl http://localhost:8000/beepboop -d '{
"source": "astring"
}'
curl http://localhost:8000/beepboop -d '{
"source": "astring"
}'
To the handler:
const schema = z.object({
source: z.string(),
});

app.post("/beepboop", zValidator("json", reapSchema), (c) => {
console.log("never got here");

return c.json({ success: true });
});
const schema = z.object({
source: z.string(),
});

app.post("/beepboop", zValidator("json", reapSchema), (c) => {
console.log("never got here");

return c.json({ success: true });
});
These seems consistent with the documentation at https://github.com/honojs/middleware/tree/main/packages/zod-validator
1 Reply
ggggggg
gggggggOP2mo ago
It seems like the POST data isn't being awaited I forget to set -H "Content-Type: application/json"
Want results from more Discord servers?
Add your server