Build A RESTful HTTP API Using Golang w/ Mux | Golang Microservices Example Code Demo | InterviewDOT
Channel: Interview DOT
Date: 01/03/2020

Click here - https://www.youtube.com/channel/UCd0U_xlQxdZynq09knDszXA?sub_confirmation=1 to get notifications.

Tamil Build a RESTful HTTP API in Golang w/ Mux | Golang Code Demo | InterviewDOT

You should have some understanding of what is HTTP and what is an API.
REST is an architectural style, or design pattern, for APIs.
Who invented REST?
REST was defined by Roy Fielding, a computer scientist. He presented the REST principles in his PhD dissertation in 2000.
Before we dive into what makes an API RESTful and what constraints and rules you should follow if you want to create RESTful APIs, let’s explain 2 key terms:
Client — the client is the person or software who uses the API. It can be a developer, for example you, as a developer, can use Twitter API to read and write data from Twitter, create a new tweet and do more actions in a program that you write. Your program will call Twitter’s API. The client can also be a web browser. When you go to Twitter website, your browser is the client who calls Twitter API and uses the returned data to render information on the screen.
Resource — a resource can be any object the API can provide information about. In Instagram’s API, for example, a resource can be a user, a photo, a hashtag. Each resource has a unique identifier. The identifier can be a name or a number.
Now let’s get back to REST.
A RESTful web application exposes information about itself in the form of information about its resources. It also enables the client to take actions on those resources, such as create new resources (i.e. create a new user) or change existing resources (i.e. edit a post).
In order for your APIs to be RESTful, you have to follow a set of constraints when you write them. The REST set of constraints will make your APIs easier to use and also easier to discover, meaning a developer who is just starting to use your APIs will have an easier time learning how to do so.
REST stands for REpresentational State Transfer.
It means when a RESTful API is called, the server will transfer to the client a representation of the state of the requested resource.
For example, when a developer calls Instagram API to fetch a specific user (the resource), the API will return the state of that user, including their name, the number of posts that user posted on Instagram so far, how many followers they have, and more.
The representation of the state can be in a JSON format, and probably for most APIs this is indeed the case. It can also be in XML or HTML format.
What the server does when you, the client, call one of its APIs depends on 2 things that you need to provide to the server:
An identifier for the resource you are interested in. This is the URL for the resource, also known as the endpoint. In fact, URL stands for Uniform Resource Locator.
The operation you want the server to perform on that resource, in the form of an HTTP method, or verb. The common HTTP methods are GET, POST, PUT, and DELETE.

Go or GoLang , as it is called, is a robust system-level language used for programming across large-scale network servers and big distributed systems. Golang emerged as an alternative to C ++ and Java for the app developers in the context of what Google needed for its network servers and distributed systems.

This example shows how to use the `gorilla/mux` package to create routes with named parameters, GET/POST handlers and domain restrictions.

Package gorilla/mux implements a request router and dispatcher for matching incoming requests to their respective handler.

Golang Concurrency is extremely important at our time. It allows multiple processes running simultaneously and effectively. Golang has efficient concurrency, like C, C++, Java, and at the same time concurrency in Go is done much easier thanks to goroutines, channels, and garbage collection


Why should I learn Golang?
Go provides you high performance like C/C++, super efficient concurrency handling like Java and fun to code like Python/Perl. If you don't have any plans to learn Go, I will still say hardware limit puts pressure to us, software developers to write super efficient code.

Why is Golang so popular?
Go relies on a concurrency model called CSP ( Communicating Sequential Processes). Instead of locking variables to share memory, Golang allows you to communicate the value stored in your variable from one thread to another.It's concurrency feature and easy deployment make it a popular choice for cloud development.

https://github.com/net-vinothkumar/restapi-go