What is REST stands for? Representational State Transfer
OK first lets consider what is REST, REST is a architecture which based on web standards and uses HTTP protocol for data communication. REST architecture treats every content as a resource. we can get text files, html pages, images, dynamic data etc. as resources. Each resource is identified by URIs. (Uniform Resource Identifier) REST uses like text, JSON and XML to represent a resource. Now you will think what is this URI, resource 🙂
we will discuss more about those later.
OK now lets talk about RESTFul web service. Before talk about RESTFul web service we have to know what is a web service? Simply we can say, web service is a collection of protocols and standards used for exchanging data between applications or systems. why we want web service, lets think we have two software applications which written in various languages and running on various platforms. So how can we exchange data between those applications? OK now web services come to picture 😀
Now it is very easy to say what is RESTFul web service. If we use REST architecture for a web service we can call it RESTFul web service. Please keep in mind REST is not a programming language or something it is a ARCHITECTURE 🙂
Above we said REST uses HTTP protocol for data communication. RESTFul web services communicate using HTTP request and HTTP response. A client sends a message in form of a HTTP request and server responds in form of HTTP response. we call this technique as Messaging.
HTTP request has five major parts.
Verb – This indicate HTTP methods such as GET, POST, DELETE, PUT etc.
URI – we can identify the resource on server using this.
HTTP Version – This indicate HTTP version. eg:- HTTP v1.1
Request Header – This contains metadata for the HTTP request message as key-value pairs. eg:- client type, format supported by client, format of message body etc.
Request body – Message content or Resource representation.
HTTP response has four major parts.
Status/Response code – Indicate Server status for the requested resource. eg:- 404 Not found
Response Header – eg:-content length, content type, response date, server type etc.
Response body – Response message content or Resource representation.
OOOOOK I think now we know something about REST 🙂 Can you remember, above we mentioned about URI ?
Now you know URI stands for Uniform Resource Identifier. URI identifies each resource in REST architecture. Purpose of an URI is to locate a resource(s) on the server hosting the web service.
This is the format of URI
Let’s think we want to read a customer with ID# 12345, We can use,
Ohhh wait, What is this “GET”? Did you see that “GET” or you just read it 😀
I think you can remember that we have discussed about five major parts of a HTTP request. ??? scroll up and see 🙂
In that Verb part, It indicates HTTP methods such as GET, POST, DELETE, PUT etc.
OK now you know what that “GET” is. The following HTTP methods are most commonly used in a REST based architecture. we use HTTP methods to map CRUD(create,retrieve,update,delete) operations to HTTP requests.
we can use GET for retrieve information. GET method is idempotent. 🙂 another new word. idempotent is used more comprehensively to describe an operation that will produce the same results if executed once or multiple times.
simply we can say, if we execute GET method with same parameters many times, we get same result. No effects.
eg:- To read a customer with Customer ID# 12345:
Request that the resource at the URI do something with the provided entity.
POST is used to create a new entity, but it can also be used to update an entity.
eg:-To create a new product.
Store an entity at a URI. PUT can create a new entity or update an existing one. A PUT request is idempotent. Idempotency is the main difference between the expectations of PUT versus a POST request.
Request that a resource be removed; however, the resource does not have to be removed immediately. It could be an asynchronous or long-running request.
Ok now you got some idea about REST and later we can talk about more details about these HTTP methods and other things 🙂