CS396: Spring 2022

Intro to Web Development

CS396: Spring 2022

Assignments > Lab 5. REST API Endpoint Activity

Due on Fri, 04/29 @ 11:59PM. 5 Points.

Introduction

For this week’s lab, you will complete the tasks specificied in HW3 for the following 2 routes:

You will know that you are done when all of the tests/test_posts.py pass.

Video Walkthrough

Sarah has made a walkthrough video to help you with Lab 5. Once you go through a few routes on your own, it should get easier!

Your Tasks

Please complete the following tasks by editing your /views/posts.py file:

Method/Route Description and Examples Parameters Response Type Points
GET /api/posts All posts in the current users' feed. This includes the current user's posts, as well as the people that the current user is following. You will need to modify this endpoint to get it to work as specified.
  • limit (int, optional): Limits the number of posts returned (defaults to 20, maximum is 50)
List of Post objects 2
GET /api/posts/<int:id> The post associated with the id (already started for you). Post object 1
POST /api/posts Should create a new post (already started for you).
  • image_url: string (required)
  • caption: string
  • alt_text: string
Post Object 2
PATCH /api/posts/<int:id> Should update the post (already started for you).
  • image_url: string (optional)
  • caption: string (optional)
  • alt_text: string (optional)
User Object 1
DELETE /api/posts/<int:id> Should delete the post (already started for you). Note that the delete is configured to cascade (all associated comments, likes, bookmarks, etc. will also be deleted). User Object 1

What to turn in

Please upload your views/posts.py file. If you used any additional python files to get your code to work, please upload those as well!