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.  
  6. app.Get("/", func(c *fiber.Ctx) {
  7. // Create data struct:
  8. data := SomeStruct{
  9. name: "Grame",
  10. age: 20,
  11. }
  12.  
  13. c.JSONP(data)
  14. // => callback({"name": "Grame", "age": 20})
  15.  
  16. c.JSONP(data, "customFunc")
  17. // => customFunc({"name": "Grame", "age": 20})
  18. })