Skip to content
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

Body parser/form parser/url encoded parser by default #259

Closed
1 task done
nopeless opened this issue Dec 1, 2022 · 4 comments
Closed
1 task done

Body parser/form parser/url encoded parser by default #259

nopeless opened this issue Dec 1, 2022 · 4 comments
Labels
enhancement New feature or request idea

Comments

@nopeless
Copy link

nopeless commented Dec 1, 2022

Describe the feature

Every time I have to include some kind of form parsing it increases the development time by hours. Each time I have to find npm and find a package that works. It would be nice to have this parsed by default and exposed somewhere as a getter so developers don't have to worry about anything

Additional information

  • Would you be willing to help implement this feature?
@nozomuikuta
Copy link
Member

@pi0

FYI, Hono takes this approach (exporting a lot of default middlewares from main repository), which I agree is good DX.

@nopeless
Copy link
Author

@pi0

FYI, Hono takes this approach (exporting a lot of default middlewares from main repository), which I agree is good DX.

Thanks for responding @nozomuikuta , take a look at this issue nuxt/nuxt#15730

@nozomuikuta nozomuikuta added the enhancement New feature or request label Dec 12, 2022
@Hebilicious
Copy link
Member

Hebilicious commented Jun 30, 2023

We should probably document this or expose a similar helper,
But something that you can do without any dependencies in recent version of node.js is this :

// H3
export async function getRequestFromEvent(event: H3Event) {
  const url = new URL(getRequestURL(event))
  const method = getMethod(event)
  const body = method === "POST" ? await readRawBody(event) : undefined
  return new Request(url, { headers: getRequestHeaders(event) as any, method, body })
}

// H3
export async function getFormData(event: H3Event) {
  return (await getRequestFromEvent(event)).formData()
}

Then you can use getFormData(event) and use the .get FormData native method to read your form values.

@Hebilicious Hebilicious added the idea label Jun 30, 2023 — with Volta.net
@pi0
Copy link
Member

pi0 commented Jul 28, 2023

The new readFormData utility is available via #421. You can early test it via nightly channel (check reademe for how)

@pi0 pi0 closed this as completed Jul 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request idea
Projects
None yet
Development

No branches or pull requests

4 participants