Skip to Content
Building RESTful Web services with Go
book

Building RESTful Web services with Go

by Naren Yellavula
December 2017
Intermediate to advanced
316 pages
6h 58m
English
Packt Publishing
Content preview from Building RESTful Web services with Go

RESTful API with Gorilla Mux and MongoDB

In the previous chapters, we explored all the possible ways of building a RESTful API. We first looked into HTTP routers, then web frameworks. But as a personal choice, in order to make our API lightweight, one prefers Gorilla Mux as the default choice and mgo for the MongoDB driver. In this section, we are going to build a proper movies API with an end-to-end integration of the database and HTTP router. We saw how to create a new resource and retrieve it back using Go and MongoDB. Using that knowledge, let us write this program:

package main import ( "encoding/json" "io/ioutil" "log" "net/http" "time" "github.com/gorilla/mux" mgo "gopkg.in/mgo.v2" "gopkg.in/mgo.v2/bson" ) // DB stores the database ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Hands-On RESTful Web Services with Go - Second Edition

Hands-On RESTful Web Services with Go - Second Edition

Naren Yellavula
Microservices with Go

Microservices with Go

Alexander Shuiskov

Publisher Resources

ISBN: 9781788294287Supplemental Content