Parsing JSON Body
The Parse Data middleware parses JSON data from request bodies and converts it into a JavaScript object.
Example
Request:
fetch("/data", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ count: "10", active: "true" })
})
Server-side:
import v from "vkrun"
const vkrun = v.App()
vkrun.post("/data", (request: v.Request, response: v.Response) => {
console.log(request.body)
// Output: { count: 10, active: true }
response.status(200).end()
})
In this example:
"10"
is converted to a number."true"
is converted to a boolean.