It's time to make your own API!
Using what you have learned about Express, Express Routing, RESTful routing, CRUD operations, and Mongoose, use the Mongoose ODM to implement full CRUD functionality on a model (subject of your choosing).
- The model you choose to use should have at least three fields, in addation to the default
_id
field.
Example:
column name | type |
---|---|
_id | integer |
name | string |
widgets | integer |
purpose | string |
- Your API should be accessible via five routes:
Example:
Method | Action | URL | Functionality |
---|---|---|---|
GET | index | /widgets | list all widgets |
POST | create | /widgets | add a widget |
GET | detail/show | /widgets/:id | show one widget |
PUT | update | /widgets/:id | update one widget |
DELETE | delete | /widgets/:id | delete one widget |
You will need to:
- Fork and clone this repository!
- Run
npm init
to start your node project. - Create a
.gitignore
and add everything to ignore - Create your Express App
- Add Mongoose functionality!
Recommended Workflow:
- Stub out your routes. For the purposes of initial declaration,
res.send("test")
to make sure you're hitting them. - Link your model to your server.
- Update your routes to "do something" and make the magic happen!
Add a second model to your API. This model should relate to your first model via a 1:M relationship.
This is a great chance to familiarize yourself with the Mongoose docs to achieve your goals. They're extensive, so don't worry if you get overwhelmed! Take this as an opportunity to play around with different methods in a no-stress environment.
Once added, update your GET and POST routes for this second model which allow you do the following with your API:
- Show all elements from second model that relate to your element from first model at :id.
- Add a new element to your original model that include related elements from this second model at :id.