/express-harrypotter-lab

Primary LanguageJavaScriptOtherNOASSERTION

General Assembly Logo

Harry Potter API

Build an API of hogwarts houses and their members!

Prerequisites

  • Node
  • MongoDB and Mongoose
  • Express

Instructions

  1. Fork and clone this repository.
  2. Change into the new directory.
  3. Install dependencies.
  4. Fulfill the listed requirements.

Complete your work inside of the lib/ directory. Unless otherwise specified by an instructor, your submission is due by the time on your cohort calendar.

Requirements

This lab is divided into two parts. In the first part, you will set up your database and seed it with the JSON data provided in the db/ directory. Once that is finished, for the second part of this lab, you'll build out an API that serves the seeded data from your database.

Part 1: Seeding

We've provided you with two sets of JSON data: houses.json and characters.json. The houses data contains a member property that is an array of ObjectIDs matching objects in the characters data (the _id property).

Define a model to represent the houses inside of houses.json with a subdocument model to represent the characters in characters.json.

Once your models are defined, write a seed file that takes the data in houses.json and characters.json and seeds it into the database.

Part 2: API

Your database is now all set up, so it's time to build an API around it. Your API will need the following routes:

  1. A root route ('/') that redirects to the houses route.
  2. A houses list route ('/house') that returns a JSON array of all the houses in the database.
  3. A house detail route ('/house/5a05e2b252f721a3cf2ea33f') that returns the document for the house in the url parameter.
  4. A house create route ('/house') that a user could send a POST request to in order to create a new house.

Bonus

Query Strings

Implement query strings. This would allow someone to look up a house in the database by any property of the document. For example:

  • /house?mascot=lion
  • /house?houseGhost=The Grey Lady
  • /house?headOfHouse=Severus Snape

ref

Rather than nesting the Character model in House as a subdocument, use the model to create a character collection and house collection. Seed the data into the two collections and then relate the two with a ref. That would mean that your members property of a house would be an array of ObjectIDs from the characters collection.

Check out the documentation on how to do this.

  1. All content is licensed under a CC­BY­NC­SA 4.0 license.
  2. All software code is licensed under GNU GPLv3. For commercial use or alternative licensing, please contact legal@ga.co.