DELETE Course

Let's include an endpoint to delete a course.

Delete Course
HTTP MethodDELETE
API Endpoint/api/courses/:offeringName
Request Path ParameterofferingName
Request Query Parameter
Request Body
Response BodyJSON object (course)
Response Status200

Notice the path (endpoint) is similar to the GET request we had earlier for retrieving a course given its offering code. By convention, we return the deleted course (with status code 200).

Here are unit tests for testing this API endpoint:

@Test
public void deleteCourseWorks() throws UnirestException {
  // This test will break if "EN.601.226" does not exists in database
  final String OFFERING_NAME = "EN.601.226";
  final String URL = BASE_URL + "/api/courses/" + OFFERING_NAME;
  HttpResponse<JsonNode> jsonResponse = Unirest.delete(URL).asJson();
  assertEquals(200, jsonResponse.getStatus());
  assertNotEquals(0, jsonResponse.getBody().getArray().length());
}
@Test
public void deleteCourseNotInDatabase() throws UnirestException {
  // This test will break if "EN.000.999" exists in database
  final String OFFERING_NAME = "EN.000.999";
  final String URL = BASE_URL + "/api/courses/" + OFFERING_NAME;
  HttpResponse<JsonNode> jsonResponse = Unirest.delete(URL).asJson();
  assertEquals(404, jsonResponse.getStatus());
}

Here are the Postman requests corresponding to the above tests:

Finally, here is the route method that must be added to ApiServer.main:

delete("/api/courses/:offeringName", (req, res) -> {
  // TODO Implement me!
  return null;
});

Notice it is left out for you to implement as part of HW5.

Once you have implemented the route method, run the tests in IntelliJ to ensure they pass. Moreover, run the Postman requests to ensure the API behaves as expected.