Post Request 7 – Gin Gonic Golang Web Framework

Post Request 7 – Gin Gonic Golang Web Framework

 

Source Code

<div>
<div>// we are going to learn POST Request</div>
<div>package main</div>
<div>import "github.com/gin-gonic/gin"</div>
<div>func main() {</div>
<div>    // new router/server</div>
<div>    r := gin.Default()</div>
<div>    //r.LoadHTMLGlob("./templates/*")</div>
<div>    r.Static("/", "./")</div>
<div>    // Post request is like GET . first parameter is path .. 2nd is function</div>
<div>    r.POST("/post", func(c *gin.Context) {</div>
<div>        //user := c.DefaultPostForm("user", "unknown")</div>
<div>        // first parameter is the form field name and 2nd is default</div>
<div>        //c.String(200, "hello %s", user)</div>
<div>        //c.HTML(200, "index.tmpl", user)</div>
<div>        // 200 is statusCode and %s is to display string</div>
<div>    })</div>
<div>    r.Run()</div>
<div>}</div>
</div>

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

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: