Building RESTful API with the Gin framework

Gin-Gonic is a framework based on httprouter. We learned about 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 can be compared to another web framework in Go called Martini. All web frameworks allow us to do a lot more things such as templates and web server design, in addition to service creation.

One can install the Gin package using the following command:

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

Let's write a simple hello world program in Gin to get familiarized with the Gin constructs:

  1. First, create a file that holds our program:
touch -p $GOPATH/src/github.com/git-user/chapter4/ginExample/main.go ...

Get Hands-On RESTful Web Services with Go - Second Edition 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.