Parsing URL-encoded Form Data
The Parse Data middleware parses URL-encoded form data and converts the values into their appropriate types.
Example
Client-side:
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<{
body: {
string: string;
number: "number";
};
}>,
response: v.Response
) => {
console.log(request.body);
// Output: { string: "example", number: "42" }
response.status(200).end();
}
);In this example:
"example"remains a string."42"remains a string.