SE457 – Service-Oriented Architecture

Spring 2021

Homework 3

Due Date: May 11, 2021 5:30PM

100 points (10% of final grade)


Submit your answers to D2L by May 11, 2021 5:30PM. Late homework will not be accepted.


        The purpose of this assignment is to give you practical experience in creating a simple REST-based web service, along with experience in interacting with the web service via common client tools. In this assignment, you will get experience with the JAX-RS web services framework, as well as the curl command-line tool for issuing HTTP requests.


REST Service

In this section, you will implement a REST-based Quote of the Day web service. Your initial implementation must provide the REST equivalents of the following Java classes and methods:

        Important: While the above was written as pseudo-Java code, this was merely to illustrate its require-ments. The REST-based web service must implement the RESTful equivalent of these clases and methods, following the REST design best practices we’ve discussed in class.

        Beyond the basic behavior of the service, you must also implement the following additional RESTful web service best practices:

1. You must choose and implement a versioning strategy for your API. The strategy can be whichever strategy you prefer. See week 5’s lecture for some discussion on versioning strategies.

2. You must implement index-based pagination on the getAllQuotes() endpoint. The user of this endpoint must be able to provide the (optional) query-string parameters ?page= and ?per_page= to select which quotes they want. For example, assuming that the web service has 10 quotes with the identifiers 1, 2, . . . , 10, a request for ?page=2 and ?per_page=5 must return the quotes with identifiers 6, 7, . . . , 10.


Requirements

1. The internal set of available quotations must be pre-seeded with five initial quotations.

2. The service must be published to the endpoint http://localhost:8888/quotes.

3. The service must be written in Java using JAX-RS to appropriately annotate the web service classes and methods.

4. The service must use JSON as its data exchange format

5. The service must implement the REST best practices in modelling resources, representations, methods, etc.

6. The service must implement a clear versioning strategy.

7. The service must implement pagination on the getAllQuotes() endpoint as specified above. The pagination must remain correct even as quotes are added, updated, and removed.

8. I must be able to compile and run the service using Maven using the command mvn install (or equivalent). Submissions that cannot be compiled will be severely penalized.

9. Your code must have an appropriate amount of comments to describe its functionality. In a comment, it is not necessary to repeat the what (i.e. what the code is doing), but you should focus on the why or ways in which the code is non-obvious or non-self-describing. Code with zero comments will be penalized.

10. It is not necessary for the changes made by addQuote to persist after a restart of the service. We are not modelling a data storage backend with this assignment.


Demonstrating Service Behavior

You must demonstrate that the service implements the above behavior. Use the command-line tool curl to invoke methods on your REST API, and capture all requests and responses to the web service. Be sure to demonstrate both the full HTTP request and the response.


Requirements

1. You must use the command-line tool curl to invoke the API

2. Each call must include the full HTTP request and response (see the -v option in curl)

3. You must show each of the service methods in action

4. You must show pagination working

5. All output must be captured in a file and submitted as part of the assignment


Useful Links

Here are some links which may help you get started:

1. Java API for RESTful Web Services (Wikipedia)

2. Building RESTful Web Services with JAX-RS

3. Curl documentation

4. Create REST APIs with JAX-RS 2.0


Submission

Submit the following in a single ZIP file:

• Your source code for the RESTful API. It is not necessary to submit the compiled files. I will be rebuilding your project from scratch.

• A text file, Word document, or PDF demonstrating the behavior of your RESTful web service based on the curl commands above.