Params

Method can be used to get the route parameters, you could pass an optional default value that will be returned if the param key does not exist.

Defaults to empty string (""), if the param doesn’t exist.

  1. func (c *Ctx) Params(key string, defaultValue ...string) string
  1. // GET http://example.com/user/fenny
  2. app.Get("/user/:name", func(c *fiber.Ctx) error {
  3. c.Params("name") // "fenny"
  4. // ...
  5. })
  6. // GET http://example.com/user/fenny/123
  7. app.Get("/user/*", func(c *fiber.Ctx) error {
  8. c.Params("*") // "fenny/123"
  9. c.Params("*1") // "fenny/123"
  10. // ...
  11. })

Unnamed route parameters(*, +) can be fetched by the character and the counter in the route.

  1. // ROUTE: /v1/*/shop/*
  2. // GET: /v1/brand/4/shop/blue/xs
  3. c.Params("*1") // "brand/4"
  4. c.Params("*2") // "blue/xs"

For reasons of downward compatibility, the first parameter segment for the parameter character can also be accessed without the counter.

  1. app.Get("/v1/*/shop/*", func(c *fiber.Ctx) error {
  2. c.Params("*") // outputs the values of the first wildcard segment
  3. })

Returned value is only valid within the handler. Do not store any references.
Make copies or use the
Immutable setting instead. Read more…