A simple Express-based microservice to manage pets. This API allows you to add, update, retrieve, and delete pets.
- Node.js (v14 or higher)
- npm (v6 or higher)
-
Clone the repository:
git clone git@github.com:sbmars/Pet-API-Microservice.git cd Pet-API-Microservice -
Install dependencies:
npm install
Start the server:
npm run -s startThe service will start and listen on port 3000 by default. You can access it at http://localhost:3000.
- Endpoint:
GET /pet - Description: Retrieves a list of all pets.
- Response:
200 OK: Returns an array of pet objects.
-
Endpoint:
POST /pet -
Description: Adds a new pet to the list.
-
Request Body:
{ "name": "Buddy", "type": "Dog", "age": 4 } -
Response:
201 Created: Returns the newly created pet object.404 Not Found: Returns an error if the name parameter is missing.
- Endpoint:
PUT /pet - Description: Updates a pet's details using the ID provided in the request body.
- Request Body:
{ "id": 1, "name": "Buddy", "type": "Dog", "age": 5 } - Response:
200 OK: Returns the updated pet object.404 Not Found: Returns an error if the pet is not found.
- Endpoint:
PUT /pet/{id} - Description: Updates a pet's details using the ID provided in the path parameter.
- Path Parameter:
id: The ID of the pet to be updated.
- Request Body:
{ "name": "Buddy", "type": "Dog", "age": 5 } - Response:
200 OK: Returns the updated pet object.404 Not Found: Returns an error if the pet is not found.
- Endpoint:
DELETE /pet/{id} - Description: Deletes a pet using the ID provided in the path parameter.
- Path Parameter:
id: The ID of the pet to be deleted.
- Response:
204 No Content: Confirms the pet has been deleted.404 Not Found: Returns an error if the pet is not found.
All errors are returned with a JSON response containing a type and errorMessage:
{
"type": "API Exception",
"errorMessage": "Pet not found"
}