-
-
Notifications
You must be signed in to change notification settings - Fork 498
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is there a bodyParser.urlencoded({ extended: true } equivalent in Hono? #1184
Comments
Hi @charnould! Thank you for using Hono.
Hono doesn't automatically parse them as an array like Express. Actually, You can use the FormData object directly like this: const formData = await c.req.formData()
const timeslots= formData.getAll('timeslots')) I'm not sure if this will give you the result you expect, so please give it a try and let me know if it works or not. |
Thanks for your help. Unfortunately, it doesn't :-) Don't you think it could be a |
@yusukebe |
Sorry. Current my thought is it's not within Hono's scope. If you want to do that, you can make the shortcut method by yourself. But, I was thinking it's a good idea to make an "Extended Body Parser Middleware". So, it's no problem to keep this issue still opened. |
I think you can get the same result by using: import qs from 'qs';
// ...
const text = await c.req.text()
const data = qs.parse(text); |
@yusukebe is it possible to add const body = await c.req.json({ extended: true }); and inside the async json<T = any>(parse:? { extended?: boolean; options?: Nonullable<unknown> }): Promise<T> {
const body = await this.cachedBody('json');
if (!parse || !parse.extended) return body;
const qs = require('qs');
return qs.parse(body, parse?.options);
} we also can create our own implementation of if someone agree with this idea, probably will try to make a PR for it |
Hi @krsbx, Thank you for the suggestion. But, the answer is no – we can't add Firstly, Hono should not depends on external libraries. Secondly, introducing functionality like |
@yusukebe how about if I make a PR where a middleware reassign the |
Hi @krsbx, I think it's not good for a middleware to extend the |
@yusukebe, @charnould just made a PR so we can have some sort of |
Hello,
I'm making my move from
Express
/node.js
toHono
/Bun
, and it feels refreshing!Some stuff are really nice and useful: for example:
set()
/get()
!But sometimes, I'm struggling...
Consider the simple
c.req.parseBody()
below:With
express
, it is automatically parsed usingbodyParser.urlencoded({ extended: true }
, andtimeslots
is returned as an array.Maybe I'm missing something, but is there something equivalent in
hono
? Thanks.The text was updated successfully, but these errors were encountered: