RESTful Web Services are REST architecture based web services. In REST Architecture, everything is a resource. RESTful web services are lightweight, highly scalable and maintainable and are very commonly used to create APIs for web based applications.
REST stands for Representational State Transfer. REST is web standards based architecture and uses HTTP Protocol for data communication. It revolves around resource where every component is a resource and a resource is accessed by a common interface using HTTP standard methods.
REST stands for Representational State Transfer. REST is web standards based architecture and uses HTTP Protocol for data communication. It revolves around resource where every component is a resource and a resource is accessed by a common interface using HTTP standard methods.
HTTP Methods
Following well-known HTTP methods are commonly used in REST based architecture.
- GET - Provides a read-only access to a resource.
- PUT - Used to create a new resource.
- DELETE - Used to remove a resource.
- POST - Used to update an existing resource or create a new resource.
- OPTIONS - Used to get the supported operations on a resource.
A RESTful web service usually defines a URI, Uniform Resource Identifier a service, provides resource representation such as JSON and set of HTTP Methods.
We can use different tool to verify request and response of rest api .
1. Postman (Its a Chrome extension)
2. Fideler
Brief Details about Postman:
1. Install Postman extension in chrome.
2. Search Postman extension in chrome extension .
3. Click on "Launch App" button.
4. Enter URl and and select HTTP methods .
5. If needed any authorization code like OATh token enter it.
5. Enter the input parameter in Body (Different format available like Json, plain text , xml....)
6. Click on "Send" button.
7. Verify the Response.
We can use different tool to verify request and response of rest api .
1. Postman (Its a Chrome extension)
2. Fideler
Brief Details about Postman:
1. Install Postman extension in chrome.
2. Search Postman extension in chrome extension .
3. Click on "Launch App" button.
4. Enter URl and and select HTTP methods .
5. If needed any authorization code like OATh token enter it.
5. Enter the input parameter in Body (Different format available like Json, plain text , xml....)
6. Click on "Send" button.
7. Verify the Response.
What is a Resource?
REST architecture treats every content as a resource. These resources can be text files, html pages, images, videos or dynamic business data. REST Server simply provides access to resources and REST client accesses and modifies the resources. Here each resource is identified by URIs/ global IDs. REST uses various representations to represent a resource where text, JSON, XML. XML and JSON are the most popular representations of resources.
Representation of Resources
A resource in REST is similar Object in Object Oriented Programming or similar to Entity in a Database. Once a resource is identified then its representation is to be decided using a standard format so that server can send the resource in above said format and client can understand the same format.
For example, in RESTful Web Services - First Application tutorial, User is a resource which is represented using following XML format:
<user> <id>1</id> <name>Mahesh</name> <profession>Teacher</profession> </user>
Same resource can be represented in JSON format as follows:
{
"id":1,
"name":"Mahesh",
"profession":"Teacher"
}
RESTful web services make use of HTTP protocol as a medium of communication between client and server. A client sends a message in form of a HTTP Request and server responds in form of a HTTP Response. This technique is termed as Messaging. These messages contain message data and metadata i.e. information about message itself. Let's have a look on HTTP Request and HTTP Response messages for HTTP 1.1.
HTTP Request
A HTTP Request has five major parts:
- Verb- Indicate HTTP methods such as GET, POST, DELETE, PUT etc.
- URI- Uniform Resource Identifier (URI) to identify the resource on server
- HTTP Version- Indicate HTTP version, for example HTTP v1.1 .
- Request Header- Contains metadata for the HTTP Request message as key-value pairs. For example, client ( or browser) type, format supported by client, format of message body, cache settings etc.
- Request Body- Message content or Resource representation.
HTTP Response
A HTTP Response has four major parts:
- Status/Response Code- Indicate Server status for the requested resource. For example 404 means resource not found and 200 means response is ok.
- HTTP Version- Indicate HTTP version, for example HTTP v1.1 .
- Response Header- Contains metadata for the HTTP Response message as key-value pairs. For example, content length, content type, response date, server type etc.
- Response Body- Response message content or Resource representation.
Addressing refers to locating a resource or multiple resources lying on the server. It is analogous to locate a postal address of a person.
Each resource in REST architecture is identified by its URI, Uniform Resource Identifier. A URI is of following format:
<protocol>://<service-name>/<ResourceType>/<ResourceID>
Purpose of an URI is to locate a resource(s) on the server hosting the web service. Another important attribute of a request is VERB which identifies the operation to be performed on the resource. For example, in RESTful Web Services - First Application tutorial, URI ishttp://localhost:8080/UserManagement/rest/UserService/users and VERB is GET.
| HTTP Method, URI and Operation | |
|---|---|
| 1 | GET http://localhost:8080/UserManagement/rest/UserService/users Get list of users (Read Only) |
| 2 | GET http://localhost:8080/UserManagement/rest/UserService/users/1 Get User of Id 1 (Read Only) |
| 3 | PUT http://localhost:8080/UserManagement/rest/UserService/users/2 Insert User with Id 2 (Idempotent) |
| 4 | POST http://localhost:8080/UserManagement/rest/UserService/users/2 Update User with Id 2 (N/A) |
| 5 | DELETE http://localhost:8080/UserManagement/rest/UserService/users/1 Delete User with Id 1 (Idempotent) |
| 6 | OPTIONS http://localhost:8080/UserManagement/rest/UserService/users List the supported operations in web service (Read Only) |
| 7 | HEAD http://localhost:8080/UserManagement/rest/UserService/users Returns only HTTP Header, no Body. (Read Only) |
No comments:
Post a Comment