REST Service with Uniform Contract
When using a REST service, a resource is requested by the service consumer. This request occurs via a uniform contract that will be standardized throughout an IT enterprise, or at least throughout a meaningful domain of the IT enterprise. This level of standardization reduces the coupling requirements between the service consumer and services.
Let's take a look at the processing steps required by a REST service to carry out the same task:
- Issue a request for invoice data by accessing the Invoice service using a resource identifier processed via the HTTP GET method.
- Receive the requested invoice data in an HTTP response message issued by the Invoice service.
- Issue a request for customer data by accessing the Customer service using a resource identifier processed via the HTTP GET method.
- Receive the requested customer data in an HTTP response message issued by the Customer service.
- Issue a request to have the customer address added to the print queue by accessing the Printer service using a resource identifier processed via the HTTP POST method.
- Receive an HTTP response indicating that the action was successful (or not).
By using a uniform contract, REST services generally require the same number of steps to be performed. Figure 1 and the following example further explain the interaction between the service consumer and the three REST services.
Figure 1 -The steps required for a service consumer to interact with three REST services, each using the same uniform contract.
Invoice invoice = esource(http://invoice.example.com/I001).GET (Invoice.type); Customer customer = // customer id is http://customer.example.com/C081 Resource(invoice.getCustomerId()).GET(Customer.type); Resource(http://printer.example.com/queue1).POST (customer.getAddress())