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 "github.com/gin-gonic/gin" 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 c.BindJSON(&book) // 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 }
golang gingonic framework videos tutorials series
TAGS#
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 https://www.buymeacoffee.com/khan1