RESTful Web services
editA RESTFul web service is a simple web service implemented using HTTP and the principles of REST. Such a web service can be thought about as a collection of resources. The definition of such a web service can be thought of as comprising three aspects:
- The URI for the web service such as http://example.com/resources/cars
- The MIME type of the data supported by the web service. This is often JSON , XML or YAML but can be anything.
- The set of operations supported by the web service using HTTP methods including but not limited to POST, GET, PUT and DELETE.
Members of the collection are addressed by ID using URIs of the form <baseURI>/<ID>. The ID can be any unique identifier. For example if a RESTFul web service representing a collection of cars for sale might have the URI http://example.com/resources/cars . If the service uses the car registration number as the ID then a particular car might be present in the collection as http://example.com/resources/cars/yxz123
The following table shows how the HTTP verbs are typically used to implement a web service.
Resource | GET | PUT | POST | DELETE |
---|---|---|---|---|
Collection URI such as http://example.com/resources/cars/ | List the members of the collection. For example list all the cars for sale. | Not generally used. Meaning defined as replace the entire collection with another entire collection. | Create a new entry in the collection where the ID is assigned automatically by the collection. The ID created is typically returned by this operation. | Not Generally Used. Meaning defined as delete the entire collection. |
Member URI such as http://example.com/resources/cars/yxz123 | Retrieve the addressed member of the collection | Update the addressed member of the collection or create it with a defined ID. | Not Generally Used. | Delete the addressed member of the collection. |