Json – Fiber Web Framwork Golang Tutorial 2

Json – Fiber Web Framwork Golang Tutorial 2

 

 

In this tutorial we are going to send Json data to the endpoints.

You can send json data like this.

c.JSON()

Convert json to fiber map first.

fiber.Map{"message": "hello world.."}

So you can use like this

c.JSON(fiber.Map{"message": "hello world.."})

Source Code


// send json data to users
package main
import "github.com/gofiber/fiber/v2"
func main() {
    // new app/server
    app := fiber.New()
    app.Get("/", func(c *fiber.Ctx) error {
        // incorrect
        //return c.JSON({"message":"hello world.."})
        // correct way
        return c.JSON(fiber.Map{"message": "hello world.."})
    })
    // listen and server
    app.Listen(":8080")
    // let start our server Port:8080
}

Tony BB
 

TonyBB is a Coach , marketer, hypnotist and a founder of RSKVF Production who specializes in providing simple, affordable, and easy to use solutions for Life.

Click Here to Leave a Comment Below 0 comments

Leave a Reply: