Post Reqeust via HTML FORM GinGonic golang framework 11

Post Reqeust via HTML FORM GinGonic golang framework 11



Source Code

<div>// POST Request via HTML Form</div>
<div>package main</div>
<div>import ""</div>
<div>func main() {</div>
<div>    // create new router/server</div>
<div>    r := gin.Default()</div>
<div>    // register root folder for HTML Form file</div>
<div>    r.Static("/", "./")</div>
<div>    // post request</div>
<div>    r.POST("/post", func(c *gin.Context) {</div>
<div>        name := c.PostForm("name") // is the name of field</div>
<div>        // send back data received or show success</div>
<div>        c.String(200, "Hi %s", name)</div>
<div>        // lets create html form</div>
<div>    })</div>
<div>    r.Run()</div>


Source Code – Index.html

<div>&lt;!DOCTYPE html&gt;</div>
<div>&lt;html lang="en"&gt;</div>
<div>    &lt;meta charset="UTF-8"&gt;</div>
<div>    &lt;meta http-equiv="X-UA-Compatible" content="IE=edge"&gt;</div>
<div>    &lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&gt;</div>
<div>    &lt;title&gt;HTML POST REQ FORM&lt;/title&gt;</div>
<div>    &lt;form action="/post" method="post"&gt;</div>
<div>        &lt;input type="text" name="name" id=""&gt;</div>
<div>        &lt;button type="submit"&gt;submit&lt;/button&gt;</div>
<div>    &lt;/form&gt;</div>



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

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: