This project demonstrates a simple Express API with persistence functionality. It contains routes for message creation, retrieval by ID, and cleanup of messages.
The main file of this API is an Express Router which exports several routes related to handling messages. The Persistence
module is used for interacting with the database.
The following routes are defined:
Creates a new message in the system.
Request Body:
id
(string): The unique identifier for the message.message
(string): The content of the message.
Response:
A JSON object containing the ID of the newly created message.
Errors:
400
: If theid
ormessage
is not provided.500
: If any internal server error occurs.
Retrieves a message by its ID.
Parameters:
id
(string): The unique identifier for the message.
Response:
The message object with the specified ID.
Errors:
500
: If any internal server error occurs.
Cleans up the messages in the system.
Response:
A JSON object indicating the number of rows cleaned up.
Errors:
500
: If any internal server error occurs.
Clone the project, navigate into the directory and install dependencies:
git clone <repository-url>
cd <repository-directory>
npm install
Run the server:
npm start
The server will start running at http://localhost:3069
.
This API is not configured with any testing framework yet. If you want to test the API endpoints, you can use tools like Postman or curl.
Errors are logged to the console for debugging.
- Include a testing framework for robust testing.
- Expand the error handling to include more specific error messages and status codes.
- Add more endpoints as necessary for the application's needs.
- Add authentication/authorization for the api endpoints