Assignment Handout

Contributors: Alicia Wang, Conner Swenberg

Assignment Scope

Due Date: Monday 3/25, 11:59pm EST

You will be building a Reddit style community forum where people can make posts and make comments on posts.

1. Download Starter Code

We have provided the starting files you will need to complete this assignment for your convenience. This also simplifies your submission by just having to zip this same folder.

2. Implement API Specification

We have shown you how to use the Flask framework to set up routes and respond to network requests. Your assignment is to implement a series of routes following the provided specification for responding to sample requests. This assignment has 7 routes for you to implement. If you are struggling with the assignment, we recommend referring to the demo to see a concrete example.

pageAPI Specification

2a. Create a global variable for storing Post data

Just like we showed in the demo, we want you to create a datastore for all posts using a Python dictionary. Your keys should be integers corresponding to post ids and values should be post dictionary objects that mimic the data shown in the API Specification.

You may also pre-populate your dictionary with data for testing purposes.

2b. Implement routes

Reference the demo for specifics on defining route syntax. We recommend approaching routes in the order they appear in the API specification. After defining your route and function to return a response, open up Postman and test your route. Testing with Postman simply involves creating a new request tab, entering your server's URL, choosing a request method, and clicking the Send button.

3. Submit Assignment

3a. Fill out your README.txt

A README.txt file is included in the starter code for you to fill out after completing the assignment. Also note that you will not receive extra credit for extra credit challenges you complete if you do not let us know for when we grade!

Name: Jane Smith
NetID: js123

Challenges Attempted: <all the Tiers you completed here>

3b. Make sure you have proper Python styling in your code

Common mistakes in styling are:

  • NOT HAVING documentation/comments in each of your routes (a one-line comment is sufficient!)

  • Naming variables with CamelCase instead of snake_case

  • Too much/too little empty spaces/empty lines

  • Leaving in commented code

3c. Verify your routes using Postman Tests and submit an exported JSON of them

Take some time looking through the guide to learn how to make tests using Postman. You should submit your Postman collection along with your CMS submission. The best way to get full credit for your tests is to ensure that you check that the response from your API matches what the API specification is expecting to receive. Please make sure that all your tests pass when we run your collection (make sure to clear your database before running to ensure you get the result we will get).

While that should be enough to get full credit, your tests can be cleaner and easier to change if you use variables or environments. It's up to you how much you want to learn and incorporate into your tests - the better you get at it the easier the assignments will be in the future and the likelier your API will pass the test cases we release on the first try.

If you'd prefer to learn how to use Postman through a video, here is a link to everything you'll need to know for this class; however, the audio quality is quite poor due to a technical error. If you think you would benefit from a re-recording of a Postman demo, indicate that on the feedback form and we will be happy to record one.

3d. Zip and submit your assignment files

Next, zip the starter folder and submit on CMS. For reference, your directory structure should look like the following:


For clarification, this means that you SHOULD NOT include your virtual environment or pycache file in your final submission. Doing so will lose you a few points on the project.

3e. Submit Feedback Form

To receive credit for your assignment, you must fill out the feedback form so that we can better understand how effectively we are teaching and how long students are spending on assignments.

4. Prepare for Next Lecture

Students will most benefit from our class time if they come in with a few things done.

pagePre-Class TODO's

Optional Challenges

Tier I

+1 point

Validate body content of POST requests

You've already enforced that post bodies come in with the required fields, now make sure those fields contain valid content. We will passing in malformed inputs that violate

  • type preconditions

  • logical preconditions (e.g. invalid URL*)

We are expecting a 400 Bad Request to be thrown when validating the contents as well. To ensure that your changes do not conflict with the base test cases, please create these changes in new routes under


Specifically, we are looking for changes in all post requests so




Tier II

+1 point

Allow sorting through URL parameters

URL parameters are a way to pass data through a GET request through the request URL (just like how we pass data through a POST request by using a post body). We want you to build functionality to accept a URL parameter at the end of the /api/posts/ route (now as /api/extra/posts/) in the following form:

{WHEREVER YOUR SERVER IS HOSTED}/api/extra/posts/?key1=value1&key2=value2…

Since we want to sort the most popular posts (according to number of upvotes), you will also need to implement your own route to increment the upvote value of a post.


  "upvotes": 3
Success Response
  "id": <ID>,
  "upvotes": <STORED UPVOTES OF POST WITH ID {id}> + 3,
  "title": <STORED TITLE OF POST WITH ID {id}>,
  "link": <STORED LINK OF POST WITH ID {id}>,
  "username": <STORED USERNAME OF POST WITH ID {id}>,

Make the default behavior of calling this route (making a request with no post body) be incrementing the upvotes by 1.

You will need to Google around on your own to implement this. We highly recommend trying to Google your question and find a StackOverflow post first (chances are someone has tried to do this before) and if you cannot find anything then perhaps consider the official Flask documentation (though this may be very dense to look through!). Of course, feel free to ask TAs during office hours if you are really stumped!

Please use the following naming conventions for your URL parameters:

  • Key: sort

  • Value: increasing or decreasing

So, for example, /api/extra/posts/?sort=increasing would return posts in increasing order.

Total Extra Credit Points to Gain: 3

Last updated