REST - Building Better Systems

REpresentational State Transfer (REST) in short is a simple solution for invoking Web Services through URL's

REST defines a set of architectural principles to design Web services. The RESTful Web Services focus on the system's resources, including how resource states are addressed and transferred over HTTP by a wide range of clients written in different languages.

REST is now a predominant Web service design model. REST is much simpler that the SOAP- and WSDL-based interface design.

REST style of Web Service invokes HTTP methods explicitly. The basic CRUD (create, read, update, and delete) operations are mapped with HTTP methods POST,GET,PUT,DELETE respectively.

In bad designs there is a chance of using these HTTP methods for unintended purposes, For example;

GET /addemployee?name=Chris HTTP/1.1

addemployee is a state changing operation over HTTP method ,GET. If the above request is successful, it will an employee to the database.

HTTP Servers are designed to respond to GET method to retrieve information for the data store. So from the view of HTTP servers the above usage is wrong.

Similar to Create or operations like update ,delete can be invoked in a similar way, which will cause a state change in the server.

The other side of the problem is , this will cause sever side changes if the link is crawled even un intentionally.

To overcome this, the parameter name and values can be represented as XML tags and sent as a body of the HHTP POST request.











The receiver of this request will process this and add the resource in the body as a child of the resource identified in the request URI. In the above example the employee is the resource in the request URI, and Chris will be added under employee.

This is an example for RESTful service.

To update the name of an employee, the RESTful way of doing is to send a PUT request.













The key concept behind defining Restful interface is reusing the “verbs” defined the protocol. For example, employee, parts, machine all are nouns, think of what we can do with theses nouns, it could be get employee, get parts etc. “GET” is the common verb for all the nouns. GET is already defined in the protocol. The service should not define new verbs or remote procedures.

To be more clear, instead of defining services like getemployee, getpart use the universal verb , “GET” to define these services. POST for the services like addemployee, addpart etc. For Update use the PUT request.

The URL will define the resource on which the action needs to be taken ex, employee in the case of the URL, POST /employee HTTP/1.1

The other important design concept in REST is that the body part of HTTP request should carry only the state of the resource and not to carry any name of the remote method or remote procedure.
REST design reduces dependency with the application server than the SOAP- and WSDL-based kind.

1 comment:

  1. Emperor Casino | Shootercasino
    Enjoy 인카지노 the best slots and casino games for fun or practice in a modern 제왕카지노 casino with our casino 샌즈카지노 bonus rounds. This offer can be used only on select games.

    ReplyDelete