HTTP Methods

Routes an HTTP request, where METHOD is the HTTP method of the request.

  1. // HTTP methods support :param, :optional? and *wildcards
  2. // You are required to pass a path to each method
  3. app.All(path string, handlers ...func(*Ctx)) *Fiber
  4. app.Get
  5. app.Put
  6. app.Post
  7. app.Head
  8. app.Patch
  9. app.Trace
  10. app.Delete
  11. app.Connect
  12. app.Options
  13.  
  14. // Use() will only match the beggining of each path
  15. // i.e. "/john" will match "/john/doe", "/johnnnn"
  16. // Use() does not support :param & :optional? in path
  17. app.Use(handlers ...func(*Ctx))
  18. app.Use(prefix string, handlers ...func(*Ctx)) *Fiber
  1. app.Use("/api", func(c *fiber.Ctx) {
  2. c.Set("X-Custom-Header", random.String(32))
  3. c.Next()
  4. })
  5. app.Get("/api/list", func(c *fiber.Ctx) {
  6. c.Send("I'm a GET request!")
  7. })
  8. app.Post("/api/register", func(c *fiber.Ctx) {
  9. c.Send("I'm a POST request!")
  10. })