Understanding REST

photo-1556075798-4825dfaaf498.jpg

Hey Developers, Today i'm gonna be teaching you how to make REST ful APIs using node js and express. (part 1 of 2)

what is REST api (according to internet's definition)

Representational state transfer is a software architectural style that defines a set of constraints to be used for creating Web services. Web services that conform to the REST architectural style, called RESTful Web services, provide interoperability between computer systems on the internet

Wait ! What ?

seems so confusing right? so let's dump it , i'll tell you an easy way to learn REST apis

let's say you're making a dynamic social network , most likely you'll end up by the requirement that your app needs a backend which can interact with database and insert / modify/ retrieve data and send it back to the client...

Request Response Cycle

now you need a mechanism or a intermediate worker who can request and receive data back and forth ! and that's why exactly REST api's created. to make it even more easy consider this example , 'a guy walks up to Restaurant with his girlfriend , now he have to order something' in this scenario this guy won't talk directly to the chef. what he'll do is he'll call the waiter so that he can order something. with same logic applied client is the guy who orders , chef is the server who respond with resources , and the waiter... yes! you guessed it right the waiter is REST - API the intermediate between client and server

REST is not a technology or framework

the most common mistake people make is they think that REST is some technology they need to learn in order to make a full stack application . but it's completely wrong. REST is more of convention | principle on how to write endpoints that makes sense

5 types of Request REST offers

GET : as the name suggests this request will get the resources (most likely in json/text/xml) format

POST : POST requests are generally used to sent data from client to server in body part of the request

PUT : PUT in the terms of resources means update the resource fully, it's like re-assigning a array. we completely change resource here

let old_arr = [1,2,3] // old array
old_arr = [4,5,6] // changing the value entirely

PATCH : PATCH is a partial update or a quick fix update of a resource , what i mean by that is this request it used to patch the update on existing resources , they're not meant to completely change the resources

let arr = [1,2,3,4];
arr.push(5); // notice we've just added 5 we haven't modified previous values

DELETE : this type of requests are generally used to delete the resources from server (i.e) deleting an existing user from your social network

summary

so far we've learned that REST is not a technology or a framework but it is a convention | set of principles used by web developers to make api more meaningful. we've also seen that REST works as an intermediate between client and server and supports 5 type of requests (GET,POST,PUT,PATCH,DELETE)

so this was my first blog on hash node ! That's it from my side , do let me know your feedbacks in comment section.