Sunday, August 7, 2016

Gorilla API Endpoint with MongoDB

I have already explained how to write API endpoint using Gorilla web toolkit. And also we have some experience of Go with MYSQL database. Today will write API endpoints with Gorilla and MongoDB as database.
First we need to download Golang MongoDB driver. MGo offers rich functionality as a MongoDB driver for Golang.
Then in MongoDB  will create a database called TodoList and add a collection called todolist.
In the project folder will add TodoList and TodoListItem structs.
Then add main.go file and configure routes accordingly.
TodoListGetAll function should be like below.
TodoListGetByOwner function should be like below.
TodoListUpdateItem function should be like below.
Then will format our code and build all go files. After than run the project.
Using browser access http://localhost:3000/api/todolist/. You will see an output like below.

No comments:

Post a Comment