Chapter 3. RESTful Web Services: The Client Side
Consider a familiar scenario in which a client accesses a RESTful web service:
- The client issues a GET request against a RESTful service. In general, a request to a RESTful service targets a named resource, with a URI as the name.
- If successful, this GET request results in a response document, a representation of the resource targeted in the request. The document is usually in XML or JSON, although other formats might be available. In any case, the response should be MIME-typed.
- The client extracts from the document whatever information is required for the client’s application logic.
For example, the client might be a jQuery script embedded in an HTML document. This client requests data, such as a product list, from a web service. If the request succeeds, the client extracts relevant information; for instance, the client might extract the name, category, price, and in-stock quantity of each product in the list. The client then processes the information in some appropriate way; for example, the JavaScript client might build and display an HTML table that represents the product list, with one row per product.
Each step in this sample scenario poses a challenge. The GET request must be formatted properly, and the status code of the response should be inspected to determine whether the request succeeded and, if not, why not. The toughest challenge for the client, however, may be extracting required information from the document: the ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access