Building a RESTful Web Service with Spring by Ludovic Dewailly

Building a RESTful Web Service with Spring by Ludovic Dewailly

Author:Ludovic Dewailly [Dewailly, Ludovic]
Language: eng
Format: azw3, epub, pdf
Publisher: Packt Publishing
Published: 2015-10-13T16:00:00+00:00


Note

The implementation of this service and associated classes can be downloaded from the Packt Publishing website.

The REST resource

Let's now consider the endpoint that we need to create to expose this functionality through a RESTful API. One fundamental question to answer, before proceeding with the implementation of this endpoint, is what URL will this resource be made available under? One possible approach would be to add a new endpoint to our existing rooms resource (see Chapter 3, The First Endpoint). However, since we will not be just returning a list of rooms, it isn't the most logical solution. Besides, for scalability purposes, we might want to deploy this component on a separate architecture from the Inventory Service (these concerns are discussed in Chapter 10, Scaling a RESTful Web Service). Therefore, we will use a new resource exposed under a new URL:

@RestController @RequestMapping("/availability") public class AvailabilityResource { @RequestMapping(method = RequestMethod.GET) public ApiResponse getAvailability( @RequestParam("from") String from, @RequestParam("until") String until, @RequestParam(value = "roomCategoryId", required = false) String categoryId) { // omitted } }



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.