Parameters

Route parameters are named URL segments that are used to capture the values specified at their position in the URL. The captured values can be retrieved using the Params function, with the name of the route parameter specified in the path as their respective keys.

Name of the route parameter must be made up of characters ([A-Za-z0-9_]). The hyphen (-) are not interpreted literally yet. Planned for Fiber v1.10.

Example of define routes with route parameters

  1. // Parameters
  2. app.Get("/user/:name/books/:title", func(c *fiber.Ctx) {
  3. c.Write(c.Params("name"))
  4. c.Write(c.Params("title"))
  5. })
  6. // Wildcard
  7. app.Get("/user/*", func(c *fiber.Ctx) {
  8. c.Send(c.Params("*"))
  9. })
  10. // Optional parameter
  11. app.Get("/user/:name?", func(c *fiber.Ctx) {
  12. c.Send(c.Params("name"))
  13. })