❌

Normal view

There are new articles available, click to refresh the page.
Before yesterdayMain stream

A simple guide to building REST API’s in GO

By: ashish
18 June 2019 at 11:30

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.

If you want to learn Go visit awesome-go-in-education. A curated list of resources about Go in Education. If you want to do the same but in Python read A simple guide to creating REST API’s with flask. I will be using Goland from jetbrains as my IDE.

Before we get started, a few jargon.

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.

Running β€œHello World” program

Once that is done, let us import necessary packages.

Performing imports

Let us look at the imports used one by one.

  1. encoding/json – since our API’s communications will be handled in JSON format
  2. log – will log errors
  3. net/http – We will use this package to create the API’s and communicate using HTTP protocols.
  4. 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.

  1. First we create a new variable for our multiplexer.
  2. Then we use HandleFunc to define which function will handle which API endpoint.
  3. 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.

Post Requests

Photo by Andrik Langfield on Unsplash

Let us now post some data to the server.

Note: Click here to know more about json in Go.

  1. Adding a new function and a function handler.

2. Β Creating structs that will hold our json data.

3. Writing our add function.

Putting it all together

Testing it using postman

Hope this post helped you. If you want more help, feel free to ping me @Ashish_che

Jallipatti Karadu : A Bio-Diversity Walk

11 June 2023 at 14:59

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 coloring fabrics in the olden days.

We tried to find out the color by pressing and we got Maroonish violet. In the older 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.

Stay tuned for the next blog.

❌
❌