In this studio, we’ll add additional RESTful endpoints to the LaunchCart application. It builds upon the changes we added in the Walkthrough: LaunchCart REST.
From the same launchcart project/repository that you used previously, make sure you are in the rest-walkthrough-starter branch that you used earlier today.
If you don’t have the walkthrough code, you can fetch changes from the remote and check out the rest-studio-starter branch.
Create a story branch:
(switch to the rest-studio branch)
$ git checkout rest-studio-starter
(-b will create a branch and then checkout that new branch)
$ git checkout -b rest-studio-solution
Write integration tests before coding each controller method below. In doing so, you may find the documentation for JsonPath to be useful. Also, refer to existing tests in ItemRestControllerTests.
GET /api/items endpoint can take an additional optional parameter: new/api/customers Resources/api/carts Resourcesnew Parameter to /api/items¶Add a new parameter to the GET /api/items endpoint. Note that this should work in conjunction with the price parameter, so that one, both, or neither can be used when querying the resource.
Hint
You’ll need to create one or more new query methods in ItemRepository. You might find the documentation on Spring Data JPA query creation helpful for this.
/api/customers Resources¶Add the following REST resources:
GET /api/customersGET /api/customers/{id}GET /api/customers/{id}/cartWrite integration tests before coding each controller method. When testing, be sure to test for the expected status code, content type, and response contents.
/api/carts Resources¶Add the following REST resources:
GET /api/cartsGET /api/carts/{id}PUT /api/carts/{id} - allow items to be added to a cartA cart resource should include information about its owner, as well the items contained in the cart. The PUT method should allow for items to be added and removed from the cart.
If you finish the primary studio tasks, try to enable HATEOAS for your REST controllers by referencing the Spring tutorial, Building a Hypermedia-Driven RESTful Web Service. The sections titled “Create a resources representation class” and “Create a RestController” are most relevant.
If you don’t complete each of the tasks, turn in as much as you have completed by the end of the day.