Chapter 2 – Setting up API Endpoints
- GitFlow is a branching strategy that developers can follow when using version control. To apply the GitFlow model, you need a central Git repository with two main branches:
Master: It stores the official release history.
Develop: It serves as an integration branch for features.
- A model is a normal structs with basic Go types. To declare a struct in Go, use the following format:
Type ModelName struct{ Â Â Â Â Field1 TYPE Â Â Â Â Fiel2 TYPE }
- To bind a request body into a type, we use Gin model binding. Gin supports binding of JSON, XML and YAML. Gin provides two sets of methods for binding:
Should Bind:
ShouldBindJSON()
,ShouldBindXML()
,ShouldBindYAML()
Must Bind: Binds the struct pointer using the specified binding engine. It will abort the request with HTTP 400 if any error occurs.
- First, define a route with an ID as a path parameter:
router.GET("/recipes/:id", GetRecipeHandler...