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
  • Expected Functionality
  • Get all posts
  • Create a post
  • Get a specific post
  • Delete a specific post
  • Get comments for a specific post
  • Post a comment for a specific post
  • Edit a comment for a specific post

Was this helpful?

  1. Chapters
  2. 1. Routes

API Specification

Contributors: Alicia Wang, Conner Swenberg

Values wrapped in < > are placeholders for what the field values should be. Also be sure to read the request route carefully when you implement it - typos WILL cause test cases to fail!

NOTE ABOUT ERROR RESPONSES

The server should return an error response for:

  • POST requests, if the user does not supply one of the fields in the body (e.g. title, link, username, text, etc.) with a status code of 400 (bad request)

  • Any request if the id in the URL does not exist, with a status code of 404 (not found)

Error Response
{
   "error": "Your error message here"
}

For each of the following routes, we will specify a success response that you must implement, but make sure to also implement error responses accordingly!

Expected Functionality

Get all posts

GET/api/posts/

Success Response
<HTTP STATUS CODE 200>
{
  "posts": [
    {
      "id": 0,
      "upvotes": 1,
      "title": "My cat is the cutest!",
      "link": "https://i.imgur.com/jseZqNK.jpg",
      "username": "alicia98"
    },
    {
      "id": 1,
      "upvotes": 3,
      "title": "Cat loaf",
      "link": "https://i.imgur.com/TJ46wX4.jpg",
      "username": "alicia98"
    },
    ...
  ]
}

Create a post

POST/api/posts/

Request
{
  "title": "I love my dog!",
  "link": "https://i.imgur.com/XsaLqi1.jpg",
  "username": "raahi014"
}
Success Response
<HTTP STATUS CODE 201>
{
  "id": <Incremented ID>,
  "upvotes": 1,
  "title": "I love my dog!",
  "link": "https://i.imgur.com/XsaLqi1.jpg",
  "username": "raahi014"
}

Get a specific post

GET/api/posts/{id}/

Success Response
<HTTP STATUS CODE 200>
{
  "id": <ID>,
  "upvotes": <STORED UPVOTES OF POST WITH ID {id}>,
  "title": <STORED TITLE OF POST WITH ID {id}>,
  "link": <STORED LINK OF POST WITH ID {id}>,
  "username": <STORED USERNAME OF POST WITH ID {id}>
}

Delete a specific post

DELETE/api/posts/{id}/

Success Response
<HTTP STATUS CODE 200>
{
  "id": <ID>,
  "upvotes": <STORED UPVOTES OF DELETED POST WITH ID {id}>,
  "title": <STORED TITLE OF DELETED POST WITH ID {id}>,
  "link": <STORED LINK OF DELETED POST WITH ID {id}>,
  "username": <STORED USERNAME OF DELETED POST WITH ID {id}>
}

Get comments for a specific post

GET/api/posts/{id}/comments/

Success Response
<HTTP STATUS CODE 200>
{
  "comments": [
    {
      "id": 0,
      "upvotes": 8,
      "text": "Wow, my first Reddit gold!",
      "username": "alicia98"
    },
    ...
  ]
}

Post a comment for a specific post

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

Note: comments should have globally unique IDs! That is, if a comment on one post has ID 5, no other comments, even on other posts should have an ID of 5!

Request
{
  "text": "what a cute puppy aww",
  "username": "raahi014"
}
Success Response
<HTTP STATUS CODE 201>
{
  "id": <COMMENT ID>,
  "upvotes": 1,
  "text": "what a cute puppy aww",
  "username": "raahi014"
}

Edit a comment for a specific post

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

Request
{
  "text": "what a cute puppy aww (edit): omg ty for the likes"
}
Success Response
<HTTP STATUS CODE 200>
{
   "id": <CID>,
   "upvotes": <# UPVOTES>,
   "text": "what a cute puppy aww (edit): omg ty for the likes",
   "username": <USERNAME>
}
PreviousAssignment HandoutNext2. Databases

Last updated 6 months ago

Was this helpful?