Rest Web services

Posted By : Sahil Gupta | 30-Aug-2022

REST WEB SERVICES


REST web service is a collection of open protocols and standards used for exchanging data between applications and systems. 
Web services that are based on REST Architecture are known as REST web services. These web services use HTTP methods to implement the REST architecture. A rest web service defines URI known as Uniform Resource Identifier. Rest web service provides resource representation such as JSON and HTTP Methods.

 

What is REST architecture?


REST which stands for Representational State Transfer is web-based architecture and uses a set of HTTP Protocols. First, REST was introduced by Roy Fielding in 2000.

In REST architecture, a REST Server provides access to various resources, and REST client access and modifies resources. Each resource is identified by URIs. REST uses various representations like text, JSON, and XML of which JSON is the most popular.


HTTP methods
 

Following HTTP methods are used in REST-based architecture:
GET − Provides read-only access to resources.
POST − Used to create resources.
DELETE − Used to remove resources.
PUT − Used to update created resources or create new resources.
PATCH− Used to partially update data at a resource.

HTTP Verbs

1) GET
•    Used to request data.
•    It can be cached.
•    It can be seen in the browser history.
•    It can be bookmarked.
•    GET Requests are read-only, they are called Safe operations.

2) POST
•    Used to create a new resource.
•    Data are stored in the request body. Hence don’t have a limit.
•    It can be cacheable.
•    Not safe - Since this alters the server state.

3) PUT
•    Used to create/ replace a resource.
•    Not cacheable.
•    Not safe


What is a Resource?
 

REST architecture treats every content as a resource. These resources are Text Files, Html Pages, Images or Business Data. REST Server provides access to resources and modifies the resources. The most popular representations are XML and JSON which are used to represent resources.


Following are some important points to be considered while designing a representation format of a resource in REST Web Services:-
Understandability − Both Server and Client should be able to understand the representation format of the resource.
Completeness − The format should be able to represent resources completely. 
Link ability − A resource can have a linkage to another resource, a format should be able to handle such situations


Representation of Resources
 

A resource is an Object in Object Oriented Programming or an Entity in a Database. 

For example, a user is a resource that is represented using the following XML format:-

<user>    
      <id>1</id>   
      <name>Mahesh</name> 
      <profession>Teacher</profession> 
</user> 

The same resource can be represented in JSON format as follows:-

       "id":1,  
       "name":"Mahesh",   
     "profession":"Teacher" 
}


What is URI?
 

URI or Uniform Resource Identifier is string identifier that refers to resource on the internet. It is a string of characters that are used to identify resource on the internet using location, name or both.

A URI has two subsets:-

URL (Uniform Resource Locator) 
URN (Uniform Resource Number). 

Uniform Resource Identifier contains scheme, authority, path, query, and a fragment. 
Some most common URI schemes are HTTP, HTTPs, etc.

Syntax of URI

The Syntax of URI is given below:-

scheme: [//authority]path[?query][#fragment]  


What is the URL ?
 

1. URL which is known as Uniform Resource Locator used to find location of the resource on the web.

2. URL always shows unique resource and it can be HTML page, CSS document, an image, etc.

3. URL uses protocol for accessing resource, which can be HTTP, HTTPS, FTP, etc.

4. It is referred to as the address of the website.
 

Syntax of URL
 

It is given below:

scheme: [//authority]path[?query][#fragment]  

Key differences between URI and URL

1. URI contains both URL and URN to identify the name and location or both of a resource, URL is a subset of URI and only identifies the location of the resource.
2. The example of URI is urn:isbn:0-476-27557-4, whereas the example of URL, is https://google.com.
3. The URI can be used to find resources in HTML, XML, and other files also, whereas, URL can only be used to locate web pages.
4. Each URL can be a URI, whereas all URIs cannot be URLs.

 

About Author

Author Image
Sahil Gupta

He is quite dynamic, adaptive to the environment. Always manages to come out with flying colours in challenging situation. He also inspires others to be such a dynamic personality.

Request for Proposal

Name is required

Comment is required

Sending message..