Monday, May 30, 2016

API endpoint using Gorilla

In my previous post I explained how to insert and view data from mysql database using golang. In this post I will explain how to access data from API endpoint. I will use Gorilla Web Framework for this.
First we need to install Gorilla mux routing package.
Then we need to create a struct for JSON response.
Next will write Http Request Handler function.
Next will integrate it with Gorilla Mux URL routing framework. Using regular expressions we have create the StudentByIdHandler.
You can access the student response like below.