Skip to content

Hugodol/rest-api-practice

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Kan Academy

We need to create a RESTful API for a school system. There will be teachers, students, and classes.

You will be using MongoDB and the Mongoose ODM for data persistence, and express with NodeJS to create an http web server.

First, Install MongoDB. Once installed, run the command mongod to start a local mongoDB server.

General Advice

It's highly advised to install POSTMAN to test your routes as you build it out.

Here's how one reasonable way to approach creating an API:

  1. Scaffold the app structure so that every route in the basic requirements is responding with a default response
  2. Create your mongoose models to get your data models to match your schema.
  3. Work on one route at a time according to the requirements below.
  4. Rinse and repeat

Basic Requirements

Create a RESTful API that adheres to the below documentation:

  • Teachers
{GET} /api/teachers
Lists information for every teacher
  Response
    success : BOOLEAN
    err     : STRING
    teachers: ARRAY<teacher: {
      name : STRING
      email: STRING
    }>
{GET} /api/teachers/:name
Lists the information about one teacher
  Response
    name : STRING
    email: STRING
{POST} /api/teachers
Creates a teacher
  Expected Body
    name : STRING
    email: STRING
  Response
    success: BOOLEAN
    err    : STRING
  • Students
{GET} /api/students
Lists information for every student
  Response
    success : BOOLEAN
    err     : STRING
    students: ARRAY<student: {
      name : STRING
      email: STRING
    }>
{GET} /api/students/:name
Lists information for one student
  Response
    success: BOOLEAN
    id     : INTEGER
    name   : STRING
    email  : STRING
    err    : STRING
{POST} /api/students
Creates a student
  Expected Body
    name : STRING
    email: STRING
  Response
    success: BOOLEAN
    err    : STRING
  • classes
{GET} /api/classes
Lists information for all classes
  Response
    success: BOOLEAN
    err    : STRING
    classes: ARRAY<class: {
      id  : INTEGER
      code: STRING
      name: STRING
    }>
{GET} /api/classes/:code
Lists information for one class
  Response
    success: BOOLEAN
    code   : STRING
    name   : STRING
    err    : STRING
{POST} /api/classes
Creates a class (codes must be unique)
  Expected Body
    code: STRING
    name: STRING
  Response
    success: BOOLEAN
    err    : STRING

Other Requirements

  • Modify the {POST} /api/students route to create classroom associations when a student is created.

Note: Because we are working with MongoDB–a noSQL database–we have the option of storing an array of associated information on the students model itself.

Mongoose may have some helper utility to create associations for you. Time to look at the docs!

{POST} /api/students
Creates a student
  Expected Body
    name   : STRING
    email  : STRING
    classes: ARRAY<classCodes: STRING>
  Response
    success: BOOLEAN
    id     : INTEGER
    err    : STRING
  • Create a route for associating an existing student with a set of classes
{PUT} /api/students/:name/editClasses
Updates a student's classes
  Expected Body
    classes: ARRAY<classCodes: STRING>
  Response
    success: BOOLEAN
    id     : INTEGER
    err    : STRING

Final Requirement

Render the information using a front-end framework of your choice.

  • Create a view component to render all students
  • Create a view component to render all teachers
  • Create a view component to render all classes
  • Create a view component with a form to create a teacher & students.

Extra Credit

  • Implement client-side routing with a library appropriate for your front-end framework. Don't render all the components at once, but swap the components depending on the browser's URL address.
  • Add form validation
  • Add styling to your app

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%