Intro to Backend Development
  • Introduction
  • SP25 Syllabus
  • Apply to Take the Course
  • Getting Started
  • Weekly Feedback Form
  • Ed Discussion
  • Intro to Backend SP25 Google Calendar
  • Cheat Sheets
    • Assignment Requirements
    • Assignment FAQs
    • Error FAQs 😢
    • Concept FAQs
    • Postman
    • Command Line
    • Virtual Environment
  • Chapters
    • 1. Routes
      • Pre-Class TODO's
      • Lecture
      • Assignment Handout
      • API Specification
    • 2. Databases
      • Pre-Class TODO's
      • Lecture
      • Demo
      • Assignment Handout
      • API Specification
    • 3. Relational Databases
      • Pre-Class TODO's
      • Lecture
      • Demo
      • Assignment Handout
      • API Specification
    • 4. Abstractions
      • Pre-Class TODO's
      • Lecture
      • Demo
      • Assignment Handout
      • API Specification
    • 5. Containerization
      • Pre-Class TODO's
      • Docker Installation
      • Lecture
      • Demo
      • Assignment Handout
    • 6. Deployment
      • Lecture
      • Demo
      • Assignment Handout
    • 7. Images
      • Demo
      • Assignment Handout
    • 8. Authentication
      • Lecture
      • Demo
      • Assignment Handout
    • (Work in Progress) OAuth
      • Pre-Class TODO's
      • Lecture
      • Demo
      • OAuth 2.0 vs OpenID
      • Flask / OpenID example
  • Additional Topics
    • Git and Github
    • HackOurCampus
  • Other AppDev Courses
    • Intro to iOS Development
    • Intro to Android Development
    • Intro to Digital Product Design
  • Deprecated
    • Previous Semester Syllabi
      • FA22 Syllabus
      • SP22 Syllabus
      • FA21 Syllabus
      • SP21 Syllabus
      • FA20 Syllabus
      • SP20 Syllabus
    • Deployment Pre-Class TODO's
    • PA6 Assignment Handout
    • Deployment Demo
    • Final Project (Spring 2019)
      • Final Project Award Winners
Powered by GitBook
On this page
  • Assignment Scope
  • 1. Download Starter Code
  • 2. Implement API Specification
  • 3. Submit Assignment
  • 4. Prepare for Next Lecture
  • Optional Challenges
  • Tier I
  • Tier II
  • Total Extra Credit Points to Gain: 3

Was this helpful?

  1. Chapters
  2. 1. Routes

Assignment Handout

Contributors: Alicia Wang, Conner Swenberg

PreviousLectureNextAPI Specification

Last updated 1 month ago

Was this helpful?

Assignment Scope

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

You will be building a 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.

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.

2c. Test with provided test script

Use the provided test script to test your implementation. To run the test script, add the pa1_test.py file to your src directory, and run:

>>> python3 pa1_test.py

Remember that we are checking that your code matches the API specification exactly! Some common errors that can cause the test cases to fail:

  • Ports not matching (5000)

  • Routes misspelled

  • Forgetting to jsonify return

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!

README.txt
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

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).

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:

pa1/
 |-README.txt
 |-postman_collection.json
 |-src/
    |-app.py
    |-requirements.txt

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

4. Prepare for Next Lecture

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

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

POST/api/extra/

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

POST/api/extra/posts/

POST/api/extra/posts/{id}/comments/

POST/api/extra/posts/{pid}/comments/{cid}/

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.

POST/api/extra/posts/{id}/

Request
{
  "upvotes": 3
}
Success Response
<HTTP STATUS CODE 200>
{
  "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.

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

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

While that should be enough to get full credit, your tests can be cleaner and easier to change if you use or . 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, 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 and we will be happy to record one.

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

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 (though this may be very dense to look through!). Of course, feel free to ask TAs during office hours if you are really stumped!

Postman Tests
variables
environments
here
feedback form
feedback form
Pre-Class TODO's
Flask documentation
Reddit
API Specification
4KB
pa1_starter.zip
archive
30KB
pa1_test.py