REST API Architectural Constraints
What is REST API?
HTTP requests, such as GET, PUT, POST, and DELETE data use in RESTful API. It is an Application Program Interface(API). REpresentational state transfer(REST) can be thought of as a language of the Internet, which is used by browsers.
REST architectural module contains six constraints that are in any web service.
- Uniform Interface
- Stateless
- Cacheable
- Client-Server
- Layered System
- Code on Demand
Let's look at what are those...
1. Uniform Interface
To identify the difference between REST API and Non-REST API, this key constraint is used. When interacting with a given server, without think of the device or the application type such as a website or mobile app, is useful if there are is recommended way to communicate with these devices or applications.
Basically, there are four guidelines use in Uniform Interface. There are,
- Resource-Based: Individual resources are identified in the request is simply known as each resource must-have unique and cohesive URI and also it must be made available.
- Manipulation of Resources Through Representation: This means how the resources will be returned to the client. It can be XML, JSON, HTML, and many more. The following example describes it.
{
"name" : "Ryan Hillton",
"age" : 24,
"hobbies" : ["reading", "cycling", "music"]
}
- Self-described Messages: Each and every message includes relevant information that use to process the message. In addition to that passage of metadata is needed in the request and response. These data were similar to HTTP response code, Content-Type, etc. Eg :
GET /#!/user/raveena HTTP/1.1
User-Agent: Chrome/37.0.2062.94
Accept: application/json
Host: javadesigns.com
- Hypermedia as the Engine of Application State (HATEOAS): This needs to include all links for each and every response, so that client can easily discover other resources.
2. Stateless
A single client can send many requests to the server, but each of them must be unique and all the requests contain necessary details, so that server can identify them and proceed accordingly.
In addition to that any detail about the client, the server must not keep. Any detailed status must stay with the client - such as the sessions.
3. Cacheable
Many clients access through the same server and also requesting the same server resources, because of that it is necessary to have these responses might be in cached to avoid unnecessarily processing and notably increasing performance.
4. Client-Server
REST API should have client-server architecture. The uniform interface separates from the server. For example, clients are not concerned with data storage and it remains internal to each server, because of that client code is improved with the portability.
Servers can be simple and scalable because servers are not concerned with the user interface or user state.
5. Layered System
The client can not normally tell whether it is connected to the end server or to an intermediary server along the way. System scalability may be improved by the intermediary server and it enables the load balancing by providing shared caches. Layers also enforce security police.
6. Code on Demand (Optional)
This condition gives permission to the customer to run the selected code on demand. That means either it is an applet or scripts, its extend part of the server logic to the client. Because of that different client behave in a unique way even when using precisely
the same way.
Comments
Post a Comment