REST stands for Representational State Transfer. REST full is way to build your API, that follows REST specifications.
REST Architecture:
• REST-REpresentational State Transfer• Six Constraints:
• Resource-based
• Representation
1. Client-ServerRepresentation: The REST specification involves treating an individual useful resource and having the endpoint map to the resource. And then having sure verbs in terms of what you operate on that resource. And additionally we are sending request, receiving response.
2. Stateless
3. Cacheable
4. Uniform Interface
5. Layered System
6. Code-On-Demand
Response you want solely data. So in which layout both XML or JSON. JSON is a human readable format. REST API lets in JSON for request payload and send response in JSON format. Using HTTP headers, the HTTP protocol has a concept of request and response headers. Every HTTP request /response has the body which carries the message itself. And additionally include header values which have some information about the metadata of the messages.
The header data could to be length of the content material or date. One such possible header is Content Type. The response ought to contain a content material type header value with the value being JSON or XML. Its basically it important points what the format of the messages. The type of content material being send back is an information that’s available in the header.So customers receives the response it examines the header for this value, the content type value and then relying on what the content type value is it can parse the response body for this reason whether or not its JSON or XML or whatever like that.
HTTP: Request from the browser ship to the server. And client will get the response from the server. The necessary thing is what the format of the request and response are. This layout is described with the aid of HTTP Hyper Text Transfer Protocol.
When you enter the url in the browser it sends get request to that server. The server sends http response containing the html. Browser looks at the html and shows it.
Lets say, there is a structure on listing of small print and when we click on the submit button, in these variety of situations commonly we are growing POST request. HTTP defines the header which is current in the request and the body of the request.
Also http defines the http methods which are: GET, PUT, POST and DELETE. You can indicate what action you are doing by using HTTP methods.
* Retrieve all user GET /usersDetail about Different types of Rest API Status Code: Different types of Rest API Status Code
* Create a user POST /users
* Retrieve one User GET /users/{id }-> /users/1
* Delete a user DELETE /users/{id}-> /users/1
* Retrieve all posts for a user GET /users/{id}/posts
* Create a post for a User POST /users/{id}/posts
* Retrieve details of a post GET /users/{id}/posts/{post_id}
* PUT= Update
Http also includes http status code(200, 404 ...).
Resources: The most important in REST is something called Resources. Resource anything that would want to expose to the outside world through our application.
Example User, list of user, employee, list of employees, todo, list of todos are resources. We would assign URI to the resource.
REST does not worry about how you are representing your resource.
It can be * xml or * html or * json.
The REST architectural fashion describes six constraints. These constraints, applied to the architecture, have been firstly communicated with the aid of Roy Fielding in his doctoral dissertation and defines the foundation of RESTful-style.
Six Constraints:
• Client-Server : This concept explains that the client and the server should be separate from every other and allowed to evolve personally.
• Stateless : REST APIs are stateless, meaning that it does not save history of any request or response. Once the request is sent by the client it closes the connection and establishes the new connection to give the response.
• Cacheable : Because a stateless API can increase request overhead by handling high volume means large loads of incoming and outbound data calls, because for each request and response it creates a new connection, a REST API have to be designed to inspire the storage of cacheable data.
• Uniform Interface : The key to separate the customer from server is having a uniform interface that lets in independent evolution of the application without having the application’s services, or models and actions, tightly coupled to the API layer itself..
• Layered System : REST APIs have different layers of their architecture working together to build a hierarchy that helps create a more scalable and modular application.
• Code on Demand : Code on Demand allows for code or applets to be transmitted via the API for use within the application.
Advantages of REST:
REST has many advantages. It's easy to scale, flexible and portable and works independently from the client and server, which makes development less complex.
Summary
We have looked into REST Architecture design and its six constraints about REST API. And also we saw the advantages of REST.
No comments:
Post a Comment