In this challenge, you will design and build an API that satisfies the requirements listed under the Minimum Viable Product section.
Read these instructions carefully. Understand exactly what is expected before starting.
You are allowed, and encouraged, to collaborate with other peers. Please follow the twenty-minute rule, before seeking support from your PM and Instructor.
- Create a forked copy of this project.
- Add your project manager as collaborator on Github.
- Clone your OWN version of the repository.
- Create a new branch: git checkout -b
<firstName-lastName>. - Implement the project on your newly created
<firstName-lastName>branch, committing changes regularly. - Push commits: git push origin
<firstName-lastName>.
Follow these steps for completing your project.
- Submit a Pull-Request to merge Branch into master (student's Repository). Please don't merge your own pull request
- Add your project manager as a reviewer on the pull-request
- Your project manager will count the project as complete by merging the branch back into master.
- Do your magic!
- Build an API to let clients perform CRUD operations on
usersandposts. - Add an endpoint to retrieve the list of
postsfor auser. - Write custom
middlewareto ensure that the user'snameis upper-cased before the request reaches thePOSTorPUTroute handlers. - Use
Express Routersto organize the endpoints. You can optionally move and renamepostDb.jsanduserDb.jsto place it next to the corresponding router.
The /data/helpers folder includes helper files that you can use to manage the persistence of users and posts data. These files are userDb.js and postDb.js. Both files publish the following api:
get(): calling find returns a promise that resolves to an array of all theresourcescontained in the database.getById(): takes anidas the argument and returns a promise that resolves to theresourcewith that id if found.insert(): calling insert passing it aresourceobject will add it to the database and return the newresource.update(): accepts two arguments, the first is theidof theresourceto update and the second is an object with thechangesto apply. It returns the count of updated records. If the count is 1 it means the record was updated correctly.remove(): the remove method accepts anidas it's first parameter and, upon successfully deleting theresourcefrom the database, returns the number of records deleted.
The userDb.js helper includes an extra method called getUserPosts() that when passed a user's id, returns a list of all the posts for the user.
All helper methods return a promise.
The Database Schemas for the users and posts resources are:
| field | data type | metadata |
|---|---|---|
| id | unsigned integer | primary key, auto-increments, generated by database |
| name | string | required, unique |
| field | data type | metadata |
|---|---|---|
| id | unsigned integer | primary key, auto-increments, generated by database |
| text | text | required |
| user_id | unsigned integer | must be the id of an existing user |
We have provided test data for the resources.
- Use
create-react-appto create an application inside the root folder, name itclient. - From the React application connect to the
/api/usersendpoint in the API and show the list of users. - Add functionality to show the details of a user, including their posts, when clicking a user name in the list. Use React Router to navigate to a
/users/:idroute to show the user details. - Add styling!