ROUTER
Parameters

Router - Parameters

The Router is responsible for matching routes with the correct structure, including routes that have parameters. However, the Router itself does not handle parsing or converting these parameters. For parsing and converting route parameters, you must use the parseData module.

The parseData module ensures that route parameters are parsed correctly and made available via req.params. Without parseData, parameters in the route would not be processed or made available automatically.

Example: Route Parameters

In this example, parseData is used to parse route parameters, making them accessible in the req.params object:

  • path: /Mario/Elvio
import v from "vkrun"
 
const vkrun = v.App()
vkrun.parseData()
 
vkrun.get("/:firstName/:lastName", (req: v.Request, res: v.Response) => {
  const firstName = req.params.firstName
  // firstName equal "Mario"
 
  const lastName = req.params.lastName
  // lastName equal "Elvio"
  res.status(200).end()
})

see more about parse data: parseData documentation

Copyright © 2024 MIT by Mario Elvio