ROUTER
Paths

Router - Paths

Route paths, in combination with a request method, define the endpoints at which requests can be made. Route paths can be strings, string patterns, or wildcards (*).

String paths

This route path will match requests to the root route, /.

import v from "vkrun"
 
const vkrun = v.App()
 
vkrun.get("/", (req: v.Request, res: v.Response) => {
  res.send("root")
})

This route path will match requests to /users.

import v from "vkrun"
 
const vkrun = v.App()
 
vkrun.get("/users", (req: v.Request, res: v.Response) => {
  res.send("users")
})

Wildcard * paths

You can use the wildcard * in route paths to match any portion of the URL that follows the defined path. This is useful for handling dynamic routes where the exact path segments may vary.

For example, this route path will match requests to /wildcard/ followed by any string.

import v from "vkrun"
 
const vkrun = v.App()
 
vkrun.get("/wildcard/*", (req: v.Request, res: v.Response) => {
  res.send("wildcard route")
})

In this case:

  • /wildcard/test and /wildcard/anything will both match this route.
Copyright © 2024 MIT by Mario Elvio