RESTful Web Services - Resources

The REST architecture treats each content as a resource. These resources can be text files, HTML pages, images, videos, or dynamic business data. The REST server simply provides access to the resources, and the REST client accesses and modifies the resources. Here, each resource is identified by a URI/Global ID. REST uses various representations to represent a resource, where Text, JSON, XML. The most popular resource representations are XML and JSON.
Resource View
A resource in REST is similar to an object in object-oriented programming, or similar to an entity in a database. Once a resource is identified, its representation must be resolved using a standard format so that the server can send the resource in the aforementioned format and the client can understand the same format.
For example, in the chapter RESTful Web Services - First Application , the user is a resource that is represented in the following XML format:
1 Mahesh Teacher
The same resource can be represented in JSON format as follows:
{ "id":1, "name":"Mahesh", "profession":"Teacher" }
Good Resource Presentation
REST does not impose any restrictions on the format of the resource representation. A client may request a JSON representation, while another client may request an XML representation of the same resource on the server, and so on. The REST server is responsible for passing the resource to the client in a format that the client understands.
The following are some important points to consider when designing a resource representation format in RESTful web services.
-
Comprehensibility - Both the Server and the Client must be able to understand and use the resource representation format.
-
Completeness - The format must be able to fully represent the resource. For example, a resource may contain another resource. The format should be able to represent both simple and complex resource structures.
-
Linkability - A resource can have a link to another resource, the format must be able to handle such situations.
Comprehensibility - Both the Server and the Client must be able to understand and use the resource representation format.
Completeness - The format must be able to fully represent the resource. For example, a resource may contain another resource. The format should be able to represent both simple and complex resource structures.
Linkability - A resource can have a link to another resource, the format must be able to handle such situations.
However, nowadays most web services represent resources in either XML or JSON format. There are many libraries and tools available for understanding, parsing, and modifying XML and JSON data.