{"id":18623727,"url":"https://github.com/clifftech123/hng-task-2","last_synced_at":"2026-04-04T22:33:57.193Z","repository":{"id":193879545,"uuid":"689657138","full_name":"Clifftech123/HNG-TASK-2","owner":"Clifftech123","description":"Api  to  accept  person name us input and perform crud opration with it ","archived":false,"fork":false,"pushed_at":"2023-09-13T02:55:29.000Z","size":137,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-18T06:13:52.263Z","etag":null,"topics":["api","backend","expressjs","nodejs","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/Clifftech123.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":"2023-09-10T14:03:55.000Z","updated_at":"2023-09-15T11:36:01.000Z","dependencies_parsed_at":"2024-11-07T04:33:36.646Z","dependency_job_id":null,"html_url":"https://github.com/Clifftech123/HNG-TASK-2","commit_stats":null,"previous_names":["clifftech123/hng-rest-crud-api","clifftech123/hng-task-2"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Clifftech123%2FHNG-TASK-2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Clifftech123%2FHNG-TASK-2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Clifftech123%2FHNG-TASK-2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Clifftech123%2FHNG-TASK-2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Clifftech123","download_url":"https://codeload.github.com/Clifftech123/HNG-TASK-2/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239418576,"owners_count":19635208,"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":["api","backend","expressjs","nodejs","typescript"],"created_at":"2024-11-07T04:25:51.709Z","updated_at":"2025-11-03T18:30:29.329Z","avatar_url":"https://github.com/Clifftech123.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CRUD REST API for \"Person\" Resource\n\nWelcome to the CRUD REST API project for managing a \"person\" resource. This project allows you to perform basic CRUD (Create, Read, Update, Delete) operations on person data. The API is built with Node.js, Express, and MongoDB.\n\n## Technologies Used\n\n- Node.js\n- Express.js\n- MongoDB\n- TypeScript\n- Yarn\n\n## Overview\n\nThis project aims to create a robust REST API for managing person data. It includes endpoints for creating, reading, updating, and deleting person records. The API is designed to handle dynamic parameters, making it flexible to perform operations based on provided details.\n\n## Features\n\n- Create a new person record.\n- Retrieve person details by name.\n- Update existing person records by name.\n- Delete person records by name.\n- Dynamic parameter handling for flexible queries.\n- Secure interactions with the database to prevent common vulnerabilities.\n\n\n\n\n## Getting Started\n\n1. Clone this repository to your local machine using `git clone` or download the ZIP file and extract it to a folder.`\n\n```bash\n  git clone https://github.com/Clifftech123/hng-rest-crud-api.git\n\n```\n\n2. Install the required dependencies using\n\n```bash\n  yarn install\n```\n\n3. Create a `.env` file and configure your environment variables (e.g., database connection details).\n\n4. Run the API using\n\n```bash\n  yarn dev\n```\n\n##\n\n## API Endpoints and HTTP Methods\n\n### Create a Person\n\n- **Endpoint:** `POST  https://hngtask1-stage-2.onrender.com/api`\n\n- **Request Format:**\n\n  ```json\n  {\n    \"name\": \"Clifford Opoku  Isaiah\"\n  }\n  ```\n\n- **Response Format (Success):**\n\n```json\n{\n  \"name\": \"Clifford Opoku  Isaiah \",\n  \"_id\": \"6501030f31ce063922818171\",\n  \"__v\": 0\n}\n```\n\nThis endpoint creates a new person record in the database. The name attribute is required and must be a string. The API returns the newly created person record in the response body.\n\n- **Response Format (Error):**\n  If an number input is provided, the API returns an error message in the response body.\n\n```json\n{\n  \"error\": \"[\\n  {\\n    \\\"code\\\": \\\"invalid_type\\\",\\n    \\\"expected\\\": \\\"string\\\",\\n    \\\"received\\\": \\\"number\\\",\\n    \\\"path\\\": [\\n      \\\"name\\\"\\n    ],\\n    \\\"message\\\": \\\"Expected string, received number\\\"\\n  }\\n]\"\n}\n```\n\n- **Response Format (Error):**\n  If an invalid input is provided, the API returns an error message in the response body.\n  ```json\n  {\n    \"error\": \"Invalid input data\"\n  }\n  ```\n\n### Retrieve a Person\n\n- **Endpoint:** `GET  https://hngtask1-stage-2.onrender.com/api/:id`\n\n* Example : `GET  https://hngtask1-stage-2.onrender.com/api/6501030f31ce063922818171`\n\n* ## Request Parameters:\n  - id (string) - The ID of the person record to retrieve.\n\n- **Response Format (Success):**\n\n```json\n{\n  \"_id\": \"6501030f31ce063922818171\",\n  \"name\": \"Clifford Opoku  Isaiah \",\n  \"__v\": 0\n}\n```\n\n- **Response Format (Error - Person not found):**\n  ```json\n  {\n    \"error\": \"Person not found\"\n  }\n  ```\n\n### Update a Person\n\n- **Endpoint:** `PUT   https://hngtask1-stage-2.onrender.com/api/:id`\n\n* Example : `PUT   https://hngtask1-stage-2.onrender.com/api/6501030f31ce063922818171`\n\n- **Request Format:**\n  ```json\n  {\n    \"name\": \"Updated Name\"\n  }\n  ```\n  - ## Request Parameters:\n    - id (string) The ID of the person record to update.\n- **Response Format (Success):**\n\n```json\n{\n  \"_id\": \"6501030f31ce063922818171\",\n  \"name\": \"Updated Name \",\n  \"__v\": 0\n}\n```\n\n- **Response Format (Error - Person not found):**\n  ```json\n  {\n    \"error\": \"Person not found\"\n  }\n  ```\n\n### Delete a Person\n\n- **Endpoint:** `Delete   https://hngtask1-stage-2.onrender.com/api/:id`\n\n* Example : ` Delete   https://hngtask1-stage-2.onrender.com/api/6501030f31ce063922818171`\n\n- **Response Format (Success):** No content (204)\n  - ## Request Parameters:\n    - id (string) The ID of the person record to delete.\n- **Response Format (Error - Person not found):**\n\n```json\n{\n  \"message\": \"Person deleted successfully.\"\n}\n```\n\n## UML Diagrams\n\n- UML diagrams representing the API's class structure and entity-relationship design can be found in the `docs/UML_diagrams.png` folder.\n![UML](src/docs/Copy%20of%20Hng-backend-namw.jpeg)\n\n\n### POSTMAN API AUTOMATION TESTING\nThis project includes automated tests for each API endpoint using Postman. The tests are located in the `Postman folder` in `src/Postman` and are organized by endpoint. The tests are designed to run against a local instance of the API. To run the tests, follow the steps below.\n\n## API Points \n- **Endpoint:** `POST  https://hngtask1-stage-2.onrender.com/api`\n\n *\n* Test code \n```js\n - *  `Postman Collection name `: Post-Person-Test\n\npm.test(\"Create a Person - Status Code is 201\", function () {\n    pm.response.to.have.status(201);\n});\n\npm.test(\"Create a Person - Response  Name\", function () {\n    pm.response.to.have.jsonBody(\"name\");\n});\n```\n- **Response Format (Pass):**\n* Create a Person - Status Code is 201\n* Create a Person - Response Name\n\n\n\n- **Endpoint:** `GET  https://hngtask1-stage-2.onrender.com/api/:id`\n - *  `Postman Collection name `: Get-Person-by-id\n* Test code \n```js \npm.test(\"Response body is valid JSON\", function () {\n    pm.response.to.be.json;\n});\n\n```\n\n- **Response Format (Pass):**\n* Response body is valid JSON\n\n\n- **Endpoint:** `PUT  https://hngtask1-stage-2.onrender.com/api/:id`\n - *  `Postman Collection name `: update-person-by-id\n\n* Test code \n\n```js\npm.test(\"Update a Person - Status Code is 200\", function () {\n    pm.response.to.have.status(200);\n});\n\n\n```\n- **Response Format (Pass):**\n* Update a Person - Status Code is 200\n\n\n- **Endpoint:** `Delete  https://hngtask1-stage-2.onrender.com/api/:id`\n - *  `Postman Collection name `: Delete-Person-by-id\n\n```js\npm.test(\"Update a Person - Status Code is 404\", function () {\n    pm.response.to.have.status(404);\n});\n\n```\n- **Response Format (Pass):**\n* Update a Person - Status Code is 404\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclifftech123%2Fhng-task-2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fclifftech123%2Fhng-task-2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclifftech123%2Fhng-task-2/lists"}