This API allows you to perform CRUD (Create, Read, Update, Delete) operations on Person objects. You can interact with this API to manage information about individuals.
Before you begin, make sure you have the following prerequisites:
- Node.js and npm installed on your machine.
- A database configured and connected. This API uses Sequelize to interact with the database, so make sure to set up your database accordingly.
- Clone the repository to your local machine.
git clone https://github.com/olurocks/stage2.git
- Navigate to the project directory.
cd stage2
- Install the required dependencies.
npm install
-
Configure your database connection by editing the
config/config.json
file to match your database credentials. -
Create the database tables by running the Sequelize migration:
npx sequelize db:migrate
- Start the server.
npm run dev
- Endpoint:
POST /
- Description: Create a new person with a name and a value.
- Request Body:
{
"name": "John Doe",
"value": "42"
}
- Response:
{
"id": 1,
"name": "John Doe",
"value": "42",
"createdAt": "2023-09-11T00:00:00.000Z",
"updatedAt": "2023-09-11T00:00:00.000Z"
}
- Endpoint:
GET /:id
- Description: Retrieve a person by their ID.
- Response:
{
"id": 1,
"name": "John Doe",
"value": "42",
"createdAt": "2023-09-11T00:00:00.000Z",
"updatedAt": "2023-09-11T00:00:00.000Z"
}
- Endpoint:
PUT /:id
- Description: Update a person's name and value by their ID.
- Request Body:
{
"name": "Updated Name",
"value": "43"
}
- Response:
{
"message": "Person updated successfully"
}
- Endpoint:
DELETE /:id
- Description: Delete a person by their ID.
- Response:
{
"message": "User deleted successfully",
"deleted_user": {
"id": 1,
"name": "John Doe",
"value": "42",
"createdAt": "2023-09-11T00:00:00.000Z",
"updatedAt": "2023-09-11T00:00:00.000Z"
}
}
-
If the provided ID does not exist, you will receive a
404 Not Found
response. -
If the request body does not contain valid name and value fields, you will receive a
400 Bad Request
response. -
If there is an internal server error, you will receive a
500 Internal Server Error
response. -
To run tests run the command in your root directory
npm run test