Restful Services - Step 1

Hey Readers ! 

Let's do some simplifications ! I am writing this post to explain you something which is the core of  web services . Obviously we can't learn all the concepts of web services in a single blogpost but as the title suggests its our first step towards web services  . 

Before jumping into ocean of web services, first let us learn how to swim ! 

Internet is very underrated term now a days , But what internet means is Inter-Network i.e. network of networks , when we say a network that means  network of computers .

In this interconnected network all the flow of data is governed by some set of rules or protocols , let us take an example of network , let's say a network of teachers and students in a school , So in a school there is some standard operations that is performed every day such as which teacher will teach to which class , How many children will be there in a particular section of class etc.  Now what we see is that every operation happening in a school ( network of teachers and students ) is following some rules that each and everyone has to follow in order to function well . 

In similar fashion network of computers also follow some rules to exchange data between them, these set of rules is collectively known as HTTP( Hypertext Transfer Protocol ) . 

Suppose in our school if teachers want to exchange exam papers then it is necessary that students don't access it before exam . So to do so schools have some different standard operating procedures during exam time like students are not allowed to enter exam room or teachers are not allowed to disclose the questions to students . 

In Similar way when there is need of secure environment in network of computers like we are performing net banking , so it is necessary that our personal  data is not visible to any malicious user . for such security reasons we have another set of rules that is much secure than HTTP which is HTTPS that is Hypertext Transfer Protocol Secure 

You can check if a particular site on network uses HTTP or HTTPS  by looking its web address.

  Not Secure 
   Secure

Note - We will see http in more detail in next blogpost.

"Now that we have seen how school works , Let us learn how components on this network works which are teachers and students "

So analogous to our school example the component of internet is world wide web .Many people get confused when we talk about internet and www , they think both are  same . But you won't confuse yourself  if you remember that www ( web in short) is working on internet as teachers are working in the network called school .

When we say transfer of data on internet , it raises 3 questions .

1 . How to transfer ? ans : ( http and https )

2. What is source and destination of the data ?  ans : (servers and clients )

3 . Where is this data stored  ans : (A Database )  













The above diagram clearly explains answers of all the 3 question that one can raise . Here what we call as client is a computer that is connected to network but it just accesses the services that a server offers though a simplified interface called as front end . 

Let us view the client-server architecture using our school model, The teachers can be treated as the server while the students can be treated as a client . Let's see how student - teacher doubt clearing session happens . Well it is simple, there is single teacher is a class while there are multiple students. Now each student requests the teacher to explain something or give him some information and if the request of student is valid then teacher responds to the student according to his/her knowledge or may refer some book filled with those information . Here the books or the knowledge of the teacher is analogues to  the database which the server accesses to respond .  

Now that we are familiar with client- server architecture , we can now look what is REST.

REST is acronym of REpresentational State Transfer, But what actually Rest is ?  

Like we have discussed client-server architecture , in similar way Rest is just another architecture through which two systems can communicate now you may confuse yourself  thinking Rest is an alternative architecture to client-server architecture but it is not , rather client-server model is very core of all the web which is used by rest because client server model offers separation of  client and server and of course the database .

Now what it means is , That for any resource(websites / services etc. )  on network we can follow various approach to communicate with client and server,  apart from REST we also have another approach or way called as SOAP but we will restrict ours self to REST.

Now any communication between client and server which follow those rules which are defined for REST is called RESTful web service . To give you some clarity let us see some of the rules of REST.

1 . Property Of Separation : It says that server is not required to know the client to process its request or in simple words implementation of client side and implementation of server is separate . Also, client side code is programmed separately and server side code is programmed separately .

2. Statelessness :  It says that for client and server  communication doesn't  need to depend on the previous state of their communication or in simple words while processing request of client, server is already fed with sufficient information that is required to process that request so that server need not to bother about gathering information from any previous state of communication . That is why this property is called state-lessness

3. Property Of Cache : It says that response given by server should be cacheable so that client can use it for other similar request . 

These are 3 basic properties that a communication between client and server follows for it to be called as Rest type communication  . Although there are some more properties/rules which you can read here


This is what is required to understand to learn to create Rest APIs . In Next blogpost we will se how client - server communication happens using Rest-APIs build with Node JS .

Till then good bye ! 

Comments