Build an API of hogwarts houses and their members!
- Node
- MongoDB and Mongoose
- Express
- Fork and clone this repository.
- Change into the new directory.
- Install dependencies.
- 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.
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.
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.
Your database is now all set up, so it's time to build an API around it. Your API will need the following routes:
- A root route (
'/'
) that redirects to the houses route. - A houses list route (
'/house'
) that returns a JSON array of all the houses in the database. - A house detail route (
'/house/5a05e2b252f721a3cf2ea33f'
) that returns the document for the house in the url parameter. - A house create route (
'/house'
) that a user could send aPOST
request to in order to create a new house.
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
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.
- All content is licensed under a CCBYNCSA 4.0 license.
- All software code is licensed under GNU GPLv3. For commercial use or alternative licensing, please contact legal@ga.co.