JSONP

Sends a JSON response with JSONP support. This method is identical to JSON, except that it opts-in to JSONP callback support. By default, the callback name is simply callback.

Override this by passing a named string in the method.

  1. c.JSONP(v interface{}, callback ...string) error
  1. type SomeStruct struct {
  2. name string
  3. age uint8
  4. }
  5. app.Get("/", func(c *fiber.Ctx) {
  6. // Create data struct:
  7. data := SomeStruct{
  8. name: "Grame",
  9. age: 20,
  10. }
  11. c.JSONP(data)
  12. // => callback({"name": "Grame", "age": 20})
  13. c.JSONP(data, "customFunc")
  14. // => customFunc({"name": "Grame", "age": 20})
  15. })