Building RESTful APIs with the Gin framework

Gin-gonic is a framework based on the httprouter. We learned about the httprouter in Chapter 2, Handling Routing for Our REST Services. It is an HTTP multiplexer like Gorilla Mux, but it is faster. Gin allows a high-level API to create REST services in a clean way. Gin compares itself with another web framework called martini. All web frameworks allow us to do a lot more things such as templating and web server design, additional to service creation. Install the Gin package using the following command:

go get gopkg.in/gin-gonic/gin.v1

Let us write a simple hello world program in Gin to get familiarized with the Gin constructs. The file is ginBasic.go:

package mainimport (    "time" "github.com/gin-gonic/gin" ...

Get Building RESTful Web services with Go now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.