{"id":24711793,"url":"https://github.com/sunthecoder/create-api-endpoints","last_synced_at":"2026-04-10T00:03:25.619Z","repository":{"id":246446736,"uuid":"821159949","full_name":"SunTheCoder/Create-Api-Endpoints","owner":"SunTheCoder","description":null,"archived":false,"fork":false,"pushed_at":"2024-06-28T00:59:32.000Z","size":19,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-22T06:45:26.173Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SunTheCoder.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-06-28T00:09:02.000Z","updated_at":"2024-06-28T00:59:35.000Z","dependencies_parsed_at":"2024-06-28T01:58:40.019Z","dependency_job_id":null,"html_url":"https://github.com/SunTheCoder/Create-Api-Endpoints","commit_stats":null,"previous_names":["sunthecoder/create-api-endpoints"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/SunTheCoder/Create-Api-Endpoints","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SunTheCoder%2FCreate-Api-Endpoints","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SunTheCoder%2FCreate-Api-Endpoints/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SunTheCoder%2FCreate-Api-Endpoints/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SunTheCoder%2FCreate-Api-Endpoints/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SunTheCoder","download_url":"https://codeload.github.com/SunTheCoder/Create-Api-Endpoints/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SunTheCoder%2FCreate-Api-Endpoints/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263437345,"owners_count":23466368,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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-01-27T07:15:57.004Z","updated_at":"2025-10-17T05:03:05.173Z","avatar_url":"https://github.com/SunTheCoder.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Practice: Creating API Endpoints\n\nIn this practice, you will create a Web API server with endpoints that return\ndata as JSON instead of displaying HTML view pages in a traditional web server.\nThis server should only also accept JSON request bodies and parse them.\n\nThe Web API server should have endpoints to return all the dogs in the server\ndata, return details of a specific dog, create a new dog, edit a dog, and delete\na dog from the server data.\n\nYou can test all the route handlers you implement in Postman or by using `fetch`\nin the browser. Then, you will be able to confirm your solutions by running\nmocha tests.\n\n## Set Up\n\n1. Clone the practice from GitHub.\n2. Run `npm install` to install dependencies.\n3. Start the server by running `node server.js`.\n4. Run `npm test` to run the tests after completing each phase.\n\nTake a look at the server code in __server.js__. The skeleton code for each\nendpoint is set up for you. You will have to fill out the code for each\nendpoint using the route parameter values and the parsed JSON request body.\n\n_Note: The skeleton code for each endpoint already includes `return res.end()`,\nwhich allows the tests to run properly. As you write out your logic within each\nendpoint, you may move that line of code, but make sure each endpoint\nincludes that line before running the tests, or they may time out._\n\nNear the top of the **server.js** file, you will see the following code:\n\n```js\nconst dogs = [\n  {\n    dogId: 1,\n    name: 'Fido',\n    age: 2\n  }\n];\n\nlet nextDogId = 2;\n\nfunction getNewDogId() {\n  const newDogId = nextDogId;\n  nextDogId++;\n  return newDogId;\n}\n```\n\nThe `dogs` array of objects is your data and contain all the information about\neach dog in your server.\n\n## Parse the JSON Request Body\n\nParse the request body in the server as JSON only when the `Content-Type` header\nis `application/json`.\n\nThis code is already provided for you in the starter. Review the switch\nstatement and compare how the request body is parsed depending on the\n`content-type` of the request header.\n\n## Phase 1: GET /dogs\n\nImplement the `GET /dogs` API endpoint to return the `dogs` array as JSON.\n\nTest this endpoint in Postman or by using `fetch` in the browser.\n\n## Phase 2: GET /dogs/:dogId\n\nImplement the `GET /dogs/:dogId` API endpoint to return the object of the\nspecified dog as JSON. Find the specified dog object from the `dogs` array\nacting as the server data. (Hint: use `Array.find()` to find the specified dog\nbased on the `:dogId` route parameter.)\n\nTest this endpoint in Postman or by using `fetch` in the browser.\n\n## Phase 3: POST /dogs\n\nImplement the `POST /dogs` API endpoint to create a dog based on the body of the\nrequest. Use the return value of the `getNewDogId()` as the value of the `dogId`\nin the new dog's object. Push the new dog object to the dogs array. Return the\nnewly created dog object as a JSON response.\n\nTest this endpoint in Postman or by using `fetch` in the browser.\n\n## Phase 4: PUT or PATCH /dogs/:dogId\n\nImplement the `PUT /dogs/:dogId` API endpoint to edit the specified dog based on\nthe body of the request. Return the updated dog object as a JSON response.\n\nTest this endpoint in Postman or by using `fetch` in the browser.\n\n## Phase 5: DELETE /dogs/:dogId\n\nImplement the `DELETE /dogs/:dogId` API endpoint to delete a dog from the server\ndata. (Hint: use `Array.findIndex()` to find the array index of the dog in the\n`dogs` array. Then use `Array.splice()` to remove the dog from the `dogs` array\nusing that index.) Afterwards, return a message in JSON of\n`\"Successfully deleted\"`.\n\nTest this endpoint in Postman or by using `fetch` in the browser.\n\nConfirm your solutions for all endpoints by running `npm test`.\n# Create-Api-Endpoints\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsunthecoder%2Fcreate-api-endpoints","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsunthecoder%2Fcreate-api-endpoints","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsunthecoder%2Fcreate-api-endpoints/lists"}