-
Request:
- Method: POST
- Endpoint:
/api/people - Headers:
- Content-Type: application/json
- Body:
{ "name": "John Doe" }
-
Response:
- Status Code: 201 Created
- Body:
{ "_id": "some_unique_id", "name": "John Doe" }
-
Request:
- Method: GET
- Endpoint:
/api/people - Query Parameters (optional):
- name: String (e.g., "John Doe")
-
Response:
- Status Code: 200 OK
- Body:
[ { "_id": "some_unique_id", "name": "John Doe" } // Other person objects ]
-
Request:
- Method: GET
- Endpoint:
/api/people/{person_id}
-
Response:
- Status Code: 200 OK
- Body:
{ "_id": "some_unique_id", "name": "John Doe" }
-
Request:
- Method: PUT
- Endpoint:
/api/people/{person_id} - Headers:
- Content-Type: application/json
- Body:
{ "name": "Updated Name" }
-
Response:
- Status Code: 200 OK
- Body:
{ "_id": "some_unique_id", "name": "Updated Name" }
-
Request:
- Method: DELETE
- Endpoint:
/api/people/{person_id}
-
Response:
- Status Code: 200 OK
- Body:
{ "_id": "some_unique_id", "name": "John Doe" }
POST /api/people
Content-Type: application/json
{
"name": "John Doe",
}GET /api/people?name=John DoeGET /api/people/{person_id}PUT /api/people/{person_id}
Content-Type: application/json
{
"name": "Updated Name",
}DELETE /api/people/{person_id}- The API assumes that the "name" field is a string and enforces this validation.
To set up and deploy the API, follow these steps:
-
Clone the GitHub repository:
git clone https://github.com/your-username/your-repo.git
-
Navigate to the project directory:
cd your-repo -
Install dependencies:
npm install
-
Start the API locally:
node app.js
-
Access the API at
http://localhost:3000.
To test the api run npm run test
