Post Reqeust JSON Data 10 – Gin Gonic Golang Web Framework

Post Reqeust JSON Data 10 – Gin Gonic Golang Web Framework



// post request -- Json Data post request
package main
import ""
type Books struct {
    Bookname string
    Author   string
    Price    string
// make every first letter capital in struct. otherwise errors 🙂
// create varible
// lets create an array/ slice
var books []Books
func main() {
    // create new router
    r := gin.Default()
    // new post request ... it has 2 args ... path & function
    r.POST("/", func(c *gin.Context) {
        var book Books // now we can bind this variable and send back
        // we need a struct/model.. Let create one
        // sending response to user
        // now append all the results in this array...
        books = append(books, book)
        c.JSON(200, books) // we are done // change book to books array/slice
        // you send success message.. like c.String(200,"success...")
    r.Run() // default port is 8080


gin gonic tutorial
gin-gonic / examples
gin-gonic documentation
gin framework tutorial
gin web framework
gin router
golang gin context
gin router group

###Buy Me a Coffee

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: