Accepts

Checks, if the specified extensions or content types are acceptable.

Based on the request’s Accept HTTP header.
  1. c.Accepts(types ...string) string
  2. c.AcceptsCharsets(charsets ...string) string
  3. c.AcceptsEncodings(encodings ...string) string
  4. c.AcceptsLanguages(langs ...string) string
  1. // Accept: text/*, application/json
  2. app.Get("/", func(c *fiber.Ctx) {
  3. c.Accepts("html") // "html"
  4. c.Accepts("text/html") // "text/html"
  5. c.Accepts("json", "text") // "json"
  6. c.Accepts("application/json") // "application/json"
  7. c.Accepts("image/png") // ""
  8. c.Accepts("png") // ""
  9. })

Fiber provides similar functions for the other accept headers.

  1. // Accept-Charset: utf-8, iso-8859-1;q=0.2
  2. // Accept-Encoding: gzip, compress;q=0.2
  3. // Accept-Language: en;q=0.8, nl, ru
  4. app.Get("/", func(c *fiber.Ctx) {
  5. c.AcceptsCharsets("utf-16", "iso-8859-1")
  6. // "iso-8859-1"
  7. c.AcceptsEncodings("compress", "br")
  8. // "compress"
  9. c.AcceptsLanguages("pt", "nl", "ru")
  10. // "nl"
  11. })