:art: Golang and REST APIs

:art: Golang and REST APIs

- 1 min

There are several Web services available on the internet. Many web services, like Twilio and Facebook, make their data accessible to third-party applications through an application programming interface (API). One of the most popular ways to build APIs is the REST(REpresentational Stateless Transfer) architecture style.

This post will be a good primer for a GoLang programmer looking to integrate any web-service APIs.

In this post, I shall show a working source code and a docker container image to get started quickly.

Use below two commands to see the example in action.

make build-container 
make test-container


Provide a sample example code for RESTful Web Services in Go.


Please refer to Makefile and Dockerfile for install and build instructions.

    make install
    make build
    make build-container


Use Gorilla Mux to configure the HTTP Server

Restful Methods

  1. POST
     router.HandleFunc("/event", createEvent).Methods("POST")
  2. GET
     router.HandleFunc("/", homeLink)
     router.HandleFunc("/events", getAllEvents).Methods("GET")
     router.HandleFunc("/events/{id}", getOneEvent).Methods("GET")
  3. PATCH
     router.HandleFunc("/events/{id}", updateEvent).Methods("PATCH")
     router.HandleFunc("/events/{id}", deleteEvent).Methods("DELETE")


Next Steps

Follow the below links for the source code and Dockerfile

Example Source Code



Docker Image

I hope that these references will make getting started extremely easy.


Web Resources

Satya Dillikar

Satya Dillikar

Hands-on Software Architect with extensive experience developing and delivering distributed enterprise-class mission-critical software applications.

DISCLAIMER: All views expressed on this site are my own and do not represent the opinions of any entity whatsoever with which I have been, am now, or will be affiliated. Any collateral used is referenced in the Web Resources or others sections on this page. The information provided on this website does not constitute investment advice, financial advice, or trading advice.

comments powered by Disqus