MP7
Interacting Web Services
Due dates may be found on the schedule.

1 Overview

In this MP you will both build and use web service APIs. In particular,

The code comes with a simple web front-end that lets you interact with your completed service through your web browser.

2 Initial Files

In your CS 340 directory, merge the initial starting files with the following commands:

git fetch release
git merge release/mp7 --allow-unrelated-histories -m "Merging initial files"

2.1 Python Libraries

This MP uses several Python libraries. You can install all required libraries by running:

(Note the commands are identical, except that Windows requires the use of py to invoke Python while macOS requires python3.)

3 Courses Microservice

We have fully implemented a course meeting time microservice for you. You can find it in the courses_microservice directory. This, like the microservice you will implement, uses flask to automate many of the tedious parts of running a webserver.

3.1 Running the microservice

cd into the courses_microservice directory and then do one of the following:

Either way, it should print out something like

Running on http://127.0.0.1:34000/ (Press CTRL+C to quit)

and then wait for you to use it.

3.2 Using the microservice

On a GET request to the path /<subject>/<number>/, the microservice will respond with a JSON object with three keys: course, Start Time and Days of Week. For example, the following is the result of a request to /CS/340/:

{
  "course": "CS 340",
  "Days of Week": "TR",
  "Start Time": "12:30 PM"
}

If the microservice is unable to find the course, it will return a 404 and JSON with an error key:

{
  "course": "CS 300",
  "error": "No course data available for CS 300"
}

Assuming you’ve run flask on port 34000, you can open a browser and try this out by visiting

You can also use it with the requests library, which is what the microservice you implement will do.

4 Machine Problem

Your task for this MP is to complete the flask app.py route for POST /weather that will respond with the weather forecast for the next meeting of the class provided in the request. Specifically:

Additionally, complete the flask app.py route for GET /weatherCache to return a JSON representation of your cache. Specifically,

5 Testing Your Application

A frontend has been provided for you to test your web application. To run your service, you must do three things in three different windows:

5.1 Testing Suggestions

Ensure that your server works for courses many days in the future AND for courses later the same day. (Ex: If you check your service at 9:00am for your 1:00pm class, it should report weather back for the 1:00pm class that same day.)

Test several different courses:

5.2 Automated Tests via pytest

Only once you have tested it in the web browser and ensured your caching works, you can run automated testing. IMPORTANT: If you run this test suite without caching the NWS forecast, you may be automatically timed out by the NWS server and won’t be able to run tests for several hours.

Once you have made absolutely certain you are using your cached weather forecast for each request after the first, you can run the automated tests:

This test suite checks the accuracy of your forecasts by contacting a checking service on a course VM. As such, it can only be run on campus, on your VM, or over the university VPN.

6 Submission

Once you have locally passed all the tests, you will need to submit and grade your code. First commit using the standard git commands:

git add -A
git commit -m "MP submission"
git push

6.1 Grading

The initial grading is done via a manual GitHub Action. You MUST complete this step before the deadline to earn any points for the MP:

6.2 Points

Point weights can be found in the autograding results in the GitHub action.