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 courses
  • Create a course
  • Get a specific course
  • Delete a specific course
  • Create a user
  • Get a specific user
  • Add a user to a course
  • Create an assignment for a course

Was this helpful?

  1. Chapters
  2. 4. Abstractions

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.

Expected Functionality

Get all courses

GET/api/courses/

Response
<HTTP STATUS CODE 200>
{
    "courses": [
        {
            "id": 1,
            "code": "CS 1998",
            "name": "Intro to Backend Development",
            "assignments": [ <SERIALIZED ASSIGNMENT WITHOUT COURSE FIELD>, ... ],
            "instructors": [ <SERIALIZED USER WITHOUT COURSES FIELD>, ... ],
            "students": [ <SERIALIZED USER WITHOUT COURSES FIELD>, ... ]
        },
        {
            "id": 2,
            "code": "CS 1110",
            "name": "Intro to Computer Science: Python",
            "assignments": [ <SERIALIZED ASSIGNMENT WITHOUT COURSE FIELD>, ... ],
            "instructors": [ <SERIALIZED USER WITHOUT COURSES FIELD>, ... ],
            "students": [ <SERIALIZED USER WITHOUT COURSES FIELD>, ... ]
        }
        ...
    ]
}

It is important that you return the serialized relationships WITHOUT the course field. If you attempt to return them with the course field still there, your code will end up in an infinite loop. This is because your course, when returning its relationships (say, instructors), asks the instructors which courses they teach, which will then cause those courses to return their instructors, etc.

Create a course

POST/api/courses/

Request
{
    "code": "CS1998",
    "name": "Intro to Backend Development"
}
Response
<HTTP STATUS CODE 201>
{
    "id": <ID>,
    "code": "CS1998",
    "name": "Intro to Backend Development",
    "assignments": [],
    "instructors": [],
    "students": []
}

If the client does not provide a code or name or both, respond with an error message with status code 400.

Get a specific course

GET/api/courses/{id}/

Response
<HTTP STATUS CODE 200>
{
    "id": <ID>,
    "code": <STORED CODE FOR COURSE WITH ID {id}>,
    "name": <STORED NAME FOR COURSE WITH ID {id}>,
    "assignments": [ <SERIALIZED ASSIGNMENT WITHOUT COURSE FIELD>, ... ],
    "instructors": [ <SERIALIZED USER WITHOUT COURSES FIELD>, ... ],
    "students": [ <SERIALIZED USER WITHOUT COURSES FIELD>, ... ]
}

Delete a specific course

DELETE/api/courses/{id}/

Response
<HTTP STATUS CODE 200>
{
    "id": <ID>,
    "code": <STORED CODE FOR COURSE WITH ID {id}>,
    "name": <STORED NAME FOR COURSE WITH ID {id}>,
    "assignments": [ <SERIALIZED ASSIGNMENT WITHOUT COURSE FIELD>, ... ],
    "instructors": [ <SERIALIZED USER WITHOUT COURSES FIELD>, ... ],
    "students": [ <SERIALIZED USER WITHOUT COURSES FIELD>, ... ]
}

Create a user

POST/api/users/

Request
{
    "name": "Raahi Menon",
    "netid": "rm834"
}
Response
<HTTP STATUS CODE 201>
{
    "id": <ID>,
    "name": "Raahi Menon",
    "netid": "rm834",
    "courses": []
}

If the client does not provide a name or netid or both, respond with an error message.

Get a specific user

GET/api/users/{id}/

Response
<HTTP STATUS CODE 200>
{
    "id": <ID>,
    "name": <USER INPUT FOR NAME>,
    "netid": <USER INPUT FOR NETID>,
    "courses": [ <SERIALIZED COURSE WITHOUT ASSIGNMENTS, STUDENT, OR INSTRUCTOR FIELDS>, ... ]
}

The courses field should contain ALL courses that user is in, both as a student and as an instructor (remember users can be both! Just like your backend instructors!).

Add a user to a course

POST/api/courses/{id}/add/

Request
{
    "user_id": <USER INPUT>,
    "type": "student" or "instructor"
}
Response
<HTTP STATUS CODE 200>
{
    "id": <ID>,
    "code": <STORED CODE FOR COURSE WITH ID {id}>,
    "name": <STORED NAME FOR COURSE WITH ID {id}>,
    "assignments": [ <SERIALIZED ASSIGNMENT WITHOUT COURSE FIELD>, ... ],
    "instructors": [ <SERIALIZED USER WITHOUT COURSES FIELD>, ... ],
    "students": [ <SERIALIZED USER WITHOUT COURSES FIELD>, ... ]
}

The field instructors or students in the response should include the newly added user in the respective array.

Create an assignment for a course

POST/api/courses/{id}/assignment/

Request
{
    "title": "PA4",
    "due_date": 1553354209 // in Unix time (seconds since the epoch)
}
Response
<HTTP STATUS CODE 201>
{
    "id": <ASSIGNMENT ID>,
    "title": "PA4",
    "due_date": 1553354209,  // in Unix time
    "course": {
        "id": {id},
        "code": <STORED CODE FOR COURSE WITH ID {id}>,
        "name": <STORED NAME FOR COURSE WITH ID {id}>
    }
}

If the client does not provide a title or due date or both, respond with an error message (status code 400).

PreviousAssignment HandoutNext5. Containerization

Last updated 1 year ago

Was this helpful?