Created
February 21, 2023 10:32
-
-
Save mitchallen/8bf2409fe63077b2ead35faf68ca1005 to your computer and use it in GitHub Desktop.
Example of how to create a Gin POST url
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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