ashok.emit('tech')
Apr 29, 2018 • 3 min read

Let's Take Some REST

It was a long day at work. Apart from doing my regular work of development I was involved in the process of technical hiring as well. When it comes to hiring a fullstack developer in 2018, one of the prominent question is: Can you REST?

So after all the hustle I did for the day, I though to take some REST and share the idea of REST to all of you. I will keep it short, crisp and to the point, not too easy not too advanced. If you are looking for a full blown article of REST, see this.

Let’s continue talking about REST APIs (From now on consider REST as REST APIs).

What is REST?

To be very clear, it’s all about sharing data between services. At the core, REST consists of a client (asking for something)and a server (responding with proper messages to the client). Read about the client-server model.

Why you need to REST?

How to REST

So to REST, you need two primary information. Firstly, what action to perform and secondly on which resource you want to perform the action.

Now what the heck are ACTION and RESOURCE?

Everything in your application is a RESOURCE. Lets take an example of application which involves CRUD (Create, Read, Update, Delete) for users. For beginners, it’s an app that will help us in:

Our resource here is the User and the action(s) are the all the type of manipulations that we do with our users.

Coming back to the two primary information, they are the HTTP methods (the request method) and the resource URL (the request URL). More about HTTP methods

Thinking about REST

Enough about basics now. Real challenge people face when they try to REST is how to form a proper REST endpoint and give a proper name to it.

I will assume that you are good with the HTTP methods. I will show you when and how to use it along with naming resource address properly (yes the URL part I told you earlier)

Let’s begin

What will be the first step you would like to do when making a CRUD app we spoke about? I would like to add a new user.

The HTTP method for adding a new record is POST.

Did that offended you? I am sorry then. Don’t scroll down and move to other articles. I will be brutal here.

So I have seen people using POST for creating, updating and even deleting resources. DO NOT DO THIS. Please stop doing this shit! I am aware of the fact that no one is forcing you to do so but there are few guidelines, please follow them for avoiding hazards.

Proper Endpoints (API)

So a proper endpoint (API) for different actions on user resource

Are you relaxed now?

I have seen a lot of people getting confused between PUT and PATCH. Learn to use them wisely. I have already given you a hint for destroying this confusion. That’s almost the end of this post. I have left a lot of things related to REST, major one is HATEOS. I hope you will find this post helpful.

I will update this article with the following content:

Hope you find the above instructions helpful. You can mention issues, suggestions in comments below.

Post by: Ashok Dey Fullstack JavaScript engineer, crafting scalable backends!