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. func (c *Ctx) Format(body interface{}) error
  1. app.Get("/", func(c *fiber.Ctx) error {
  2. // Accept: text/plain
  3. c.Format("Hello, World!")
  4. // => Hello, World!
  5. // Accept: text/html
  6. c.Format("Hello, World!")
  7. // => <p>Hello, World!</p>
  8. // Accept: application/json
  9. c.Format("Hello, World!")
  10. // => "Hello, World!"
  11. // ..
  12. })