This project is a Node.js application that demonstrates the differences between classic and event-driven API designs.
- Clone the repository:
git clone https://<repository-url> cd event-driven-api
- Install dependencies:
npm install
To start the development server, run:
npm run devThis will start the server using ts-node-dev, which automatically restarts the server upon file changes. The application will typically be available at http://localhost:3000 (or another port if configured differently).
In the project directory, you can run the following commands:
Runs the test suite. (Currently a placeholder "test" script).
Runs the app in development mode using ts-node-dev. This will automatically restart the server when file changes are detected.
Builds the app for production to the dist folder by compiling the TypeScript code.
Starts the production server from the dist folder using node.
This application implements two different approaches for some of its API endpoints: Classic REST and Event-Driven REST.
These endpoints follow a traditional synchronous request-response pattern.
- GET /classic/users: Retrieves a list of all users.
- Parameters: None
- POST /classic/users: Creates a new user.
- Body:
{ "name": "John Doe", "email": "john.doe@example.com" }
- Body:
- GET /classic/users/:id: Retrieves a specific user by ID.
- Parameters:
id(User ID)
- Parameters:
- PUT /classic/users/:id: Updates a specific user by ID.
- Parameters:
id(User ID) - Body:
{ "name": "Jane Doe", "email": "jane.doe@example.com" }
- Parameters:
- DELETE /classic/users/:id: Deletes a specific user by ID.
- Parameters:
id(User ID)
- Parameters:
These endpoints utilize an event-driven architecture. When a request is made, an event is typically emitted, and the client might receive an immediate acknowledgment while the actual processing happens asynchronously. The client might need to subscribe to events or poll another endpoint to get the result of the operation.
- POST /event-driven/users: Initiates the creation of a new user. An event is emitted, and the user creation is processed asynchronously.
- Body:
{ "name": "John Doe", "email": "john.doe@example.com" } - Response: Acknowledgment that the user creation process has started.
- Body:
- PUT /event-driven/users/:id: Initiates an update for a specific user by ID. An event is emitted for asynchronous processing.
- Parameters:
id(User ID) - Body:
{ "name": "Jane Doe", "email": "jane.doe@example.com" } - Response: Acknowledgment that the user update process has started.
- Parameters:
- DELETE /event-driven/users/:id: Initiates the deletion of a specific user by ID. An event is emitted for asynchronous processing.
- Parameters:
id(User ID) - Response: Acknowledgment that the user deletion process has started.
- Parameters:
(Note: The event-driven GET operations might still be synchronous or might involve querying a data store that is updated by event handlers.)
Information on how to contribute to the project.
Information about the project's license.