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

[helpers] Native Request and FormData helpers #419

Closed
1 task done
Hebilicious opened this issue Jul 2, 2023 · 0 comments · Fixed by #421
Closed
1 task done

[helpers] Native Request and FormData helpers #419

Hebilicious opened this issue Jul 2, 2023 · 0 comments · Fixed by #421
Assignees
Labels
enhancement New feature or request helpers ready

Comments

@Hebilicious
Copy link
Member

Hebilicious commented Jul 2, 2023

Describe the feature

I've implemented the following in https://github.com/Hebilicious/form-actions-nuxt

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 })
}

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

Which directly enables great DX around forms :

const eventHandler = event => {
	const formData = await getFormData(event)
	const email = formData.get("email") as string
	const password = formData.get("password") as string
	return { email }
}

Additional information

  • Would you be willing to help implement this feature?
@Hebilicious Hebilicious added helpers enhancement New feature or request labels Jul 2, 2023
@Hebilicious Hebilicious self-assigned this Jul 2, 2023
@Hebilicious Hebilicious changed the title [helper] Native Request and FormData helpers [helpers] Native Request and FormData helpers Jul 2, 2023
@Hebilicious Hebilicious added the ready label Jul 4, 2023 — with Volta.net
@pi0 pi0 closed this as completed in #421 Jul 24, 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 helpers ready
Projects
None yet
1 participant