PARSE DATA
URl Encoded Form Data

Parsing URL-encoded Form Data

The Parse Data middleware parses URL-encoded form data and converts the values into their appropriate types.

Example

Request:

fetch("/form", {
  method: "POST",
  headers: { "Content-Type": "application/x-www-form-urlencoded" },
  body: "string=example&number=42"
})

Server-side:

import v from "vkrun"
 
const vkrun = v.App()
 
vkrun.post("/form", (request: v.Request, response: v.Response) => {
  console.log(request.body)
  // Output: { string: "example", number: 42 }
  response.status(200).end()
})

In this example:

  • "example" remains a string.
  • "42" is converted to a number.
Copyright © 2024 MIT by Mario Elvio