Notifications provide real-time updates to users. They are stored in Redis and support three types: messages, alerts, and reminders.
Notification Types
message - General informational messages
alert - Important alerts requiring attention
reminder - Time-based reminders
Get Notifications
Retrieve the latest 50 notifications for the authenticated user.
curl -X GET http://localhost:3000/api/notifications \
-H "Cookie: session=your-session-token"
Response
Returns an array of notification objects, sorted by creation time (newest first).
Unique notification identifier
ID of the user this notification belongs to
Notification type: message, alert, or reminder
Notification message content
Success (200)
Error (401)
[
{
"id": "f47ac10b-58cc-4372-a567-0e02b2c3d479",
"userId": "user123",
"type": "message",
"message": "Your dashboard was updated successfully",
"createdAt": "2024-01-20T15:30:00.000Z"
},
{
"id": "9e107d9d-775e-49c4-8b6d-0a5d7e8c9f2b",
"userId": "user123",
"type": "alert",
"message": "Widget configuration requires attention",
"createdAt": "2024-01-20T14:20:00.000Z"
},
{
"id": "3c185fad-8db4-4c5d-9e1f-7b8a9c0d1e2f",
"userId": "user123",
"type": "reminder",
"message": "Meeting starts in 15 minutes",
"createdAt": "2024-01-20T13:45:00.000Z"
}
]
Notifications are limited to the 50 most recent entries per user.
Create Notification
Create a new notification for the authenticated user.
curl -X POST http://localhost:3000/api/notifications \
-H "Content-Type: application/json" \
-H "Cookie: session=your-session-token" \
-d '{
"type": "message",
"message": "Your dashboard was updated successfully"
}'
Request Body
Notification type: message, alert, or reminder
Notification message content
Response
Returns the created notification object.
Success (200)
Error (400)
Error (401)
{
"id": "f47ac10b-58cc-4372-a567-0e02b2c3d479",
"userId": "user123",
"type": "message",
"message": "Your dashboard was updated successfully",
"createdAt": "2024-01-20T15:30:00.000Z"
}
Clear Notifications
Delete all notifications for the authenticated user.
curl -X DELETE http://localhost:3000/api/notifications \
-H "Cookie: session=your-session-token"
Response
Success (200)
Error (401)
Real-time Updates
Notifications support real-time delivery via WebSocket channels. When a notification is created, it’s automatically broadcast to the user’s channel:
// Subscribe to real-time notifications
const channel = realtime.channel(`user-${userId}`);
channel.on('notification.created', (notification) => {
console.log('New notification:', notification);
// Update UI with new notification
});
The real-time event payload includes:
{
"id": "f47ac10b-58cc-4372-a567-0e02b2c3d479",
"userId": "user123",
"type": "message",
"message": "Your dashboard was updated successfully",
"createdAt": "2024-01-20T15:30:00.000Z"
}
Storage
Notifications are stored in Redis using a list data structure:
- Key format:
notifications:user:{userId}
- Stored as Redis list (LPUSH for new items)
- Automatically trimmed to 100 most recent notifications
- Retrieved in reverse order (newest first)
Notifications are stored in Redis for fast access and automatic expiration. The system maintains up to 100 notifications per user, but only returns the 50 most recent via the API.