In this post we will build Β simple REST APIβs using the Go programming language. We will also be using the MUX Router. I will also explain some of the fundamentals of the language for beginners.
REST: a RESTful API uses HTTP requests to GET, PUT, POST and DELETE data.
RESTful API designing: guidelines is a must read before you continue. It talks about terminologies, endpoints, versioning status codes and so much more.
Test your environment
Let us first test the environment to check if everything is working fine. For that we will be using a simple βHello Worldβ program.
Once that is done, let us import necessary packages.
Performing imports
Let us look at the imports used one by one.
encoding/json β since our APIβs communications will be handled in JSON format
log β will log errors
net/http β We will use this package to create the APIβs and communicate using HTTP protocols.
mux β Β A powerful URL router and dispatcher for golang . A router is used to define which function will run when a particular endpoint(URL) is called.
Writing the main funciton
Do note Β In Go, := is for declaration + assignment, whereas = is for assignment only.For example, var foo int = 10 is the same as foo := 10.
First we create a new variable for our multiplexer.
Then we use HandleFunc to define which function will handle which API endpoint.
With http.ListenAndServe we define the port that your program must listen to continuously.We wrap that around log.Fatal so that all exeptions are logged.
To run your code type the following in your console go run main.go
If you face an error telling you that mux is not installed then run go get -u github.com/gorilla/mux in your console.
This blog is about my experience of the Bio-diversity walk at Jallipatti which is located south of Udumalpet with a distance of 12km.
Table of contents
Bio-diversity walk introduction
Antlion
Social Spider
Cochineal
Sunai
Conclusion
Letβs understand the Bio-diversity walk.
Bio-diversity walk in which we observe the surroundings that not only consist of human beings but also plants, water resources, animals, birds, and micro-organisms which also have an equal right to live on this earth and own it.
We normally called these Flora and Fauna, Flora refers to all plant lives and fauna refers to all animal and bird lives.
And it does not end with observation but also tries to understand its characteristics, and its impact on the food chain, climate change, etc, and passes this information to the general public.
Bio-diversity walk enables us to understand the importance and impact of this flora and fauna.
We have chosen Jallipatti Karadu, it is a small hill slope that has a nice climate and has bio-diversity species in it.
We reached this place at 6.30am and started to climb along with Vetri, a schoolboy who is interested in exploring nature, and Mukesh, my school friend who runs the youth group named βEegai Kuluβ in Kuralkuttai village which focused on seed conservation, Grama sabha awareness, Biodiversity conservation, Bird survey and Insect survey.
He is the coordinator for this walk.
In this walk, we explored the varieties of Flora and Fauna. Mukesh and Vetri explained its characteristics since they have more experience in this field.
Mostly they will explain the flora and fauna species and if they donβt know, then we will take a species photo and upload it on INaturalist and E-Bird app in which the researchers are there, they will reply back with the characteristics and scientific names of those species.
Note: I have attached a Wikipedia link to the species image. Kindly click the image to see more details about these species.
Antlion
The first thing I learned in this Bio-diversity walk is Kulinari (Antlion), in which Kuli refers to the hole and Nari refers to Jackal which is meant for intelligent pranksters.
The Antlion
The Antlion is called a Jackal because of its intelligent method of capturing its prey by digging funnel-shaped pits in loose material with a soft layer so that if prey falls in the hole, it canβt escape it.
The Antlion further developed as an insect same as alike Dragonfly.
Social Spider
The next thing I had learned is the Social spider.
Usually, we have seen a spider in our homes which builds a web and it is seen as a solo player.
But, there are spiders who live in groups called colonies. It surprised me.
Here, the spiders used the prey not only for consumption but also for strengthening and maintenance of webs.
These webs were too sticky and even I forced hard to remove them from my cap(My cap got the web when I try to take the photo on another Flora).
Cochineal
It is an insect covered by a white layer (marked in a red circle) which is traditionally used for coloringfabrics in the olden days.
We tried to find out the color by pressing and we got Maroonish violet. In theolder days, people used to carry these groups of insects and made them dry by exposing them to sunlight. Once it gets dry, they will grind it to make colors.
After observing all of this, we have reached the top of the slope, there we viewed the Thirumoorthi dam and the ambiance is so good. Peaceful place with cold and heavy winds(my cap got wings to fly).
Sunai
We also found βSunaiβ which is the water body in the rock that wonβt dry. We have found out that the frogs in it.
Also, we have seen monkeys(grey langur) in which its body is grey with black face. I have seen this on the Discovery channel so far.
After all of this, we sat on the rock which have a better view of Thirumoorthi dam and the border spotted between the reserve forest and revenue forest.
Vetri brings snacks and we discussed the bio-diversity of that place and shared our own opinions.
Then the time is 10.30am. Itβs hard to leave this beautiful place. When we stepped down the slope, we have seen the Eagle.
Itβs surprising because earlier we had seen a flying Eagle. But this Eagle is flying but it doesnβt move forward or backward. It simply resists the wind against it and stands in the sky.
May be because it spots the prey, or it is gaining the energy to fly upwards.
Within 30 minutes, we stepped down the hill slope with so many memories.
Conclusion
To conclude, this Bio-Diversity walk was about knowledge transfer and opinion sharing in a peaceful environment with an awesome climate and with our beloved flora and fauna friends.
Thanks, Mukesh for introducing this awesome location, and the photos credit goes to him.
Thank you, everyone, for patiently reading this blog.