Restfull Services

So, Today I going to explain about RESTfull services. First we take a look about what is REST.

REST
What is REST? In long term, Representational State Transfer. REST is an architectural style and its used by all of modern web applications. we use REST for create more lightweight, scalable and maintainable web applications. Its based on resources such as multimedia items, documents and information etc.
     URL
     Resources are uniquely identified by a URL (Unique Resource Identifier) 
    ex.
          https://www.w3schools.com/css/img_fjords.jpg
          by this URL, we locate (expose) "img_fjords.jpg" for any one in internet. so that  
          resource is uiquely identified by that url.
                NOTE: There can be many URL for single resource

We use JSON or XML to pass data between server and client.


RESTfull Services 
Up to now, we have got some idea about what is REST. Lets begin with our main topic. 
In simple word, RESTfull service is a service based on REST. We use RESTfull services to communicate between client and server in more convenient way.

These are features of RESTfull Services
  • Uniform Interface
  • Stateless
  • Cacheble 
  • Client-Server
  • Layered System

Stateless
When communicating between server and client, server will not store any information about client. To identify client uniquely, client send it's information with the request in each time. So all session status are also stored in client.

Cacheble
When there are many requests from clients, Server has to handle so many requests. So that its good if have intermediate server to handle frequent requests. Those are caching servers. There can be many clients requests same request. So the each time server has to process. But caching servers will identify and store server's response for that like requests. So load for the server will reduced

Client-Server
We use REST to make communication between client and server.

In simply, we can locate each resource(it can be image, web page, data set etc. ) using a URL and add some methods to manipulate them.
There are many REST Methods.
  • GET
  • POST
  • PUT
  • DELETE
  • OPTIONS
For example,
we have some resource named students. Think it is a data set. If we want to read we use GET method.
URL: http://localhost/myApi/students
Method: GET


If we want to update that data set, we call PUT method
URL: http://localhost/myApi/students
Method: PUT

if we want to insert data into data set, we call POST method
URL: http://localhost/myApi/students
Method: POST

If we call this url directly from web browser, it will call GET method. Rather than that, there are many rest clients available for free. Ex RestClient for Firefox, Postman for chrome. So we can send POST, PUT, DELETE etc using this clients.

Using these REST methods are not rules. For example, we can use POST for updates, reading, deletions also. But using correct method is a coding convention. Using best practice will make code quality in good level and also some times performance.

Thank you for reading this post.
I hope you understood about REST services

Comments

Popular posts from this blog

CSRF Defence - Synchronizer Token Pattern Demo

Lets read emails in gmail using oAuth 2.0 (Application demo)

How to view queries executed in MySQL?