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.


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

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