CRUD REST API in Iris (a framework for golang)

iris-golang goopher…super fast! https://iris-go.com/images/icon.svg

“Please can you test this API with postman to see if it is returning the right responses?”

two years ago this sounded like rocket science to me. I definitely would have needed a video tutorial or medium article (oh yeah stackoverflow - the life saver) to carry out this task.

basically, APIs are “like a bank you cannot see. one without interface, yet it is configured to meet certain needs or answer your questions” says Ewere Ediagboya (Senior SRE/Devops Engineer).

Obviously a lot of tools out there can definitely provide this kind of bank. It all then lies on the developer’s choice. But then choices can be influenced cause as man itself is a product of influence.

When choosing tools to write APIs, nodeJs, python, PHP and a couple of other languages have taken the forefront in the quest to be the golden boy with speed being their best selling points.

Why should I use Iris?
  1. It is a golang framework . The current fastest programming language built by google
  2. Cross platform. Write once, run anywhere….waoh
  3. Service oriented — It’s easy to build microservices with Iris.
  4. It is freaking fast…

lets see an example CRUD app to showcase its prowess

Tools:

  • iris — you could install by running “go get github.com/kataras/iris”
  • mgo (a mongodb package for golang)
  • vscode
  • Postman

First we import our packages (even though golang flags unused imports, but we can ignore the warnings for now.) and define the model for our Database.

Secondly we connect to mongodb (ensure mongodb is running on your machine) and create our http server.

thirdly we create our base enpoint

Run this code and test with your postman you should see this. take note of the “Time” and “size”

Now lets us create basic CRUD functions. (NB: msisdn means phone number)

And we are live!!!

Simple readable codes. CRUD API with less line of codes!

Link to Github repo below.