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.  
  3. app.Get("/", func(c *fiber.Ctx) {
  4. c.Accepts("html") // "html"
  5. c.Accepts("text/html") // "text/html"
  6. c.Accepts("json", "text") // "json"
  7. c.Accepts("application/json") // "application/json"
  8. c.Accepts("image/png") // ""
  9. c.Accepts("png") // ""
  10. })

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.  
  5. app.Get("/", func(c *fiber.Ctx) {
  6. c.AcceptsCharsets("utf-16", "iso-8859-1")
  7. // "iso-8859-1"
  8.  
  9. c.AcceptsEncodings("compress", "br")
  10. // "compress"
  11.  
  12. c.AcceptsLanguages("pt", "nl", "ru")
  13. // "nl"
  14. })