{"id":32563062,"url":"https://github.com/blevs/node-api-iii","last_synced_at":"2026-07-04T03:33:48.257Z","repository":{"id":44075633,"uuid":"206459860","full_name":"Blevs/node-api-iii","owner":"Blevs","description":null,"archived":false,"fork":false,"pushed_at":"2023-01-11T01:39:12.000Z","size":655,"stargazers_count":0,"open_issues_count":10,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-29T02:56:46.516Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Blevs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-09-05T02:42:28.000Z","updated_at":"2019-09-05T19:27:06.000Z","dependencies_parsed_at":"2023-02-08T21:46:20.504Z","dependency_job_id":null,"html_url":"https://github.com/Blevs/node-api-iii","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Blevs/node-api-iii","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Blevs%2Fnode-api-iii","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Blevs%2Fnode-api-iii/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Blevs%2Fnode-api-iii/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Blevs%2Fnode-api-iii/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Blevs","download_url":"https://codeload.github.com/Blevs/node-api-iii/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Blevs%2Fnode-api-iii/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35109210,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-04T02:00:05.987Z","response_time":113,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-10-29T02:56:23.125Z","updated_at":"2026-07-04T03:33:48.237Z","avatar_url":"https://github.com/Blevs.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Building an API using a Node.js and Express Middleware\n\nIn this challenge, you build an API and write custom middleware that satisfies the requirements listed under the `Minimum Viable Product` section.\n\n## Instructions\n\n**Read these instructions carefully. Understand exactly what is expected before starting.**\n\nYou are allowed, and **encouraged**, to collaborate with other peers. Please follow the twenty-minute rule, before seeking support from your PM and Instructor.\n\n## Project Set Up\n\n- [ ] Create a forked copy of this project.\n- [ ] Add your project manager as collaborator on Github.\n- [ ] Clone your OWN version of the repository.\n- [ ] Create a new branch: git checkout -b `\u003cfirstName-lastName\u003e`.\n- [ ] Implement the project on your newly created `\u003cfirstName-lastName\u003e` branch, committing changes regularly.\n- [ ] Push commits: git push origin `\u003cfirstName-lastName\u003e`.\n\nFollow these steps for completing your project.\n\n- [ ] Submit a Pull-Request to merge \u003cfirstName-lastName\u003e Branch into master (student's Repository). **Please don't merge your own pull request**\n- [ ] Add your project manager as a reviewer on the pull-request\n- [ ] Your project manager will count the project as complete by merging the branch back into master.\n- [ ] Do your magic!\n\n## Minimum Viable Product\n\n1. Write and implement four custom `middleware` functions, detailed below.\n1. Build an API to let clients perform CRUD operations on `users`.\n1. Add endpoints to retrieve the list of `posts` for a `user` and to store a new `post` for a `user`.\n\n#### Custom Middleware Requirements\n\n- `logger()`\n  - `logger` logs to the console the following information about each request: request method, request url, and a timestamp\n  - this middleware runs on every request made to the API\n\n- `validateUserId()`\n  - `validateUserId` validates the user id on every request that expects a user id parameter\n  - if the `id` parameter is valid, store that user object as `req.user`\n  - if the `id` parameter does not match any user id in the database, cancel the request and respond with status `400` and `{ message: \"invalid user id\" }`\n\n- `validateUser()`\n  - `validateUser` validates the `body` on a request to create a new user\n  - if the request `body` is missing, cancel the request and respond with status `400` and `{ message: \"missing user data\" }`\n  - if the request `body` is missing the required `name` field, cancel the request and respond with status `400` and `{ message: \"missing required name field\" }`\n\n- `validatePost()`\n  - `validatePost` validates the `body` on a request to create a new post\n  - if the request `body` is missing, cancel the request and respond with status `400` and `{ message: \"missing post data\" }`\n  - if the request `body` is missing the required `text` field, cancel the request and respond with status `400` and `{ message: \"missing required text field\" }`\n\n### Database Persistence Helpers\n\nThere are two helper files that you can use to manage the persistence of _users_ and _posts_ data. These files are `users/userDb.js` and `posts/postDb.js`. Both files publish the following api:\n\n- `get()`: calling find returns a promise that resolves to an array of all the `resources` contained in the database.\n- `getById()`: takes an `id` as the argument and returns a promise that resolves to the `resource` with that id if found.\n- `insert()`: calling insert passing it a `resource` object will add it to the database and return the new `resource`.\n- `update()`: accepts two arguments, the first is the `id` of the `resource` to update and the second is an object with the `changes` to apply. It returns the count of updated records. If the count is 1 it means the record was updated correctly.\n- `remove()`: the remove method accepts an `id` as it's first parameter and, upon successfully deleting the `resource` from the database, returns the number of records deleted.\n\nThe `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`.\n\n**All helper methods return a promise.**\n\n#### Database Schemas\n\nThe _Database Schemas_ for the `users` and `posts` resources are:\n\n##### Users\n\n| field | data type        | metadata                                            |\n| ----- | ---------------- | --------------------------------------------------- |\n| id    | unsigned integer | primary key, auto-increments, generated by database |\n| name  | string           | required, unique                                    |\n\n##### Posts\n\n| field   | data type        | metadata                                            |\n| ------- | ---------------- | --------------------------------------------------- |\n| id      | unsigned integer | primary key, auto-increments, generated by database |\n| text    | text             | required                                            |\n| user_id | unsigned integer | required, must be the `id` of an existing `user`              |\n\nWe have provided test data for the resources.\n\n## Stretch Goals\n\n- Add the Post Router\n  - Implement all endpoints and middleware within `posts/postRouter.js`\n\n- Create a React App\n  - Use `create-react-app` to create an application inside the root folder, name it `client`.\n  - From the React application connect to the `/api/users` endpoint in the API and show the list of users.\n  - 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/:id` route to show the user details.\n  - Add styling!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblevs%2Fnode-api-iii","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fblevs%2Fnode-api-iii","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblevs%2Fnode-api-iii/lists"}