Push Notifications API
Overview
The Push Notifications API enables Web Push notifications for Cloudillo. It uses the VAPID (Voluntary Application Server Identification) protocol to securely deliver notifications to users’ browsers when they’re offline.
Push notifications are sent when actions are received for the user while they are not connected via WebSocket.
Endpoints
Get VAPID Public Key
GET /api/auth/vapid
Get the VAPID public key for subscribing to push notifications. The key is automatically generated on first request if it doesn’t exist.
Authentication: Required
Response:
| Field | Type | Description |
|---|---|---|
vapidPublicKey |
string | Base64-encoded VAPID public key |
Example:
Register Subscription
POST /api/notifications/subscription
Register a push notification subscription. The subscription is stored and used to send notifications when the user is offline.
Authentication: Required
Request:
| Field | Type | Required | Description |
|---|---|---|---|
subscription.endpoint |
string | Yes | Push service endpoint URL |
subscription.expirationTime |
number | No | Expiration timestamp (Unix milliseconds) |
subscription.keys.p256dh |
string | Yes | P-256 public key (base64url) |
subscription.keys.auth |
string | Yes | Auth secret (base64url) |
Response:
| Field | Type | Description |
|---|---|---|
id |
number | Subscription ID for later deletion |
Example:
Unregister Subscription
DELETE /api/notifications/subscription/{id}
Remove a push notification subscription. The subscription will no longer receive notifications.
Authentication: Required
Path Parameters:
| Parameter | Type | Description |
|---|---|---|
id |
number | Subscription ID to delete |
Response: 204 No Content
Example:
Complete Integration Example
Notification Settings
Users can control which notification types they receive through the Settings API:
| Setting | Type | Description |
|---|---|---|
notify.push.message |
boolean | Receive notifications for new messages |
notify.push.mention |
boolean | Receive notifications when mentioned |
notify.push.reaction |
boolean | Receive notifications for reactions |
notify.push.connection |
boolean | Receive notifications for connection requests |
notify.push.follow |
boolean | Receive notifications for new followers |
Example:
Web Push Standards
The implementation follows these RFCs:
| RFC | Title |
|---|---|
| RFC 8292 | VAPID for Web Push |
| RFC 8188 | Encrypted Content-Encoding for HTTP |
| RFC 8291 | Message Encryption for Web Push |
See Also
- Settings API - Notification preferences
- WebSocket API - Real-time notifications when online
- Push Notification Architecture - System internals