March 2019
Beginner to intermediate
324 pages
7h 17m
English
The method that we'll create in this section, handles a POST request; here, we expect to receive a JSON document from the client that we need to decode before we can process the request. Let's assume that our client sends a JSON document that represents the customer. The code to decode the JSON object will look like the following code block:
func (h *Handler) SignIn(c *gin.Context) { if h.db == nil { return } var customer models.Customer err := c.ShouldBindJSON(&customer)}
The c.ShouldBindJSON(...) method is provided to us by the *gin.Context type. Its main purpose is to extract JSON documents from our HTTP request body, and then parse it to the provided argument. In our case, the provided argument was a ...
Read now
Unlock full access