Build API Service using Go


Build API service using Go is very easy

Here is the simple API service that I create using Go and Gin as the web framework

package main
import "github.com/gin-gonic/gin"
func main() {
    g := gin.Default()
    g.GET("/get", func(c *gin.Context) {
c.JSON(200, gin.H{
"message": "get"
})
})
    g.POST("/post", func(c *gin.Context) {
c.JSON(200, gin.H{
"message": "post"
})
})
    g.PATCH("/patch", func(c *gin.Context) {
c.JSON(200, gin.H{
"message": "patch"
})
})
    g.DELETE("/delete", func(c *gin.Context) {
c.JSON(200, gin.H{
"message": "delete"
})
})
    g.Run()
}

Put code above into your main file and run it on terminal go run app yourfile.go

Your program will be run web server that server at port8080 try to make request to there and you will see response from server.

That’s it as simple as that.

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.