Format

Performs content-negotiation on the Accept HTTP header. It uses Accepts to select a proper format.

If the header is not specified or there is no proper format, text/plain is used.
  1. c.Format(body interface{})
  1. app.Get("/", func(c *fiber.Ctx) {
  2. // Accept: text/plain
  3. c.Format("Hello, World!")
  4. // => Hello, World!
  5.  
  6. // Accept: text/html
  7. c.Format("Hello, World!")
  8. // => <p>Hello, World!</p>
  9.  
  10. // Accept: application/json
  11. c.Format("Hello, World!")
  12. // => "Hello, World!"
  13. })