This guide explains how to use the Real-Time Notification System, including its API endpoints and the accompanying frontend interface.
The backend provides several endpoints for managing notifications. Here are the details:
Endpoint: GET /notif/send
- Query Parameter:
message
(String): The content of the notification.
- Example:
http://localhost:8080/notif/send?message=Hello, World!
- Response:
A confirmation message, e.g.,
notification sent: Hello, World!
Endpoint: GET /notif
- Produces:
text/event-stream
- Description: Streams real-time notifications using Server-Sent Events (SSE).
Endpoint: GET /notif/history
- Description: Returns a list of all past notifications.
- Response:
[ { "id": 1, "message": "Hello, World!", "timestamp": "2024-12-25T12:00:00" } ]
Endpoint: DELETE /notif/clear
- Description: Clears all past notifications.
- Response:
A confirmation message, e.g.,
notification history cleared!
Endpoint: GET /notif/search
- Query Parameter:
keyword
(String): The keyword to search for in notifications.
- Example:
http://localhost:8080/notif/search?keyword=Hello
- Response: A list of notifications matching the keyword.
Endpoint: GET /notif/summary
- Description: Returns the total number of notifications sent.
- Response:
A message, e.g.,
Total notifications sent: 5
Endpoint: PUT /notif/update/{id}
- Path Parameter:
id
(Integer): The ID of the notification to update.
- Query Parameter:
newMessage
(String): The new content for the notification.
- Example:
http://localhost:8080/notif/update/1?newMessage=Updated Message
- Response:
A confirmation message, e.g.,
notification updated: Updated Message
The frontend displays real-time notifications using a simple web page. Follow these steps to use it:
- Open the
index.html
file in a browser.
- Notifications will automatically appear in the list as they are sent.
- Ensure the backend server is running at
http://localhost:8080/notif
. - Notifications will be streamed to the frontend in real time.
-
Start the Backend:
- Run the Spring Boot application.
- Ensure it listens on
http://localhost:8080
.
-
Open the Frontend:
- Open the provided HTML file in your browser.
-
Send Notifications:
- Use the
/notif/send
endpoint or any API testing tool (e.g., Postman) to send notifications.
- Use the
-
View Notifications:
- Notifications will appear instantly on the web page.