Skip to content

Instantly share code, notes, and snippets.

@mitchallen
Created February 21, 2023 10:32
Show Gist options
  • Save mitchallen/8bf2409fe63077b2ead35faf68ca1005 to your computer and use it in GitHub Desktop.
Save mitchallen/8bf2409fe63077b2ead35faf68ca1005 to your computer and use it in GitHub Desktop.
Example of how to create a Gin POST url
r.POST("/users", func(c *gin.Context) {
var user struct {
Name string `json:"name"`
Email string `json:"email"`
}
if err := c.BindJSON(&user); err != nil {
c.JSON(400, gin.H{"error": err.Error()})
return
}
// TODO: create user in database
c.JSON(201, gin.H{"message": "User created"})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment