Push Notification Implementation Using Service Worker & Web Push Protocol
- HTTPS enabled site
- Service Worker (Client)
- Web Push (Server)
npm install
-
Run the Web Push server
node app.js
-
Serve the client app with any http server
cd client python -m SimpleHTTPServer 8888
-
Send notification to the subscribed users Simple notification
curl -XPOST -H 'Content-Type: application/json' http://localhost:3000/send -d ' { "notification": { "title": "Push Notification", "body": "Hey Dude!", "icon": "icon.png", "url": "https://www.appzcoder.com/" } } '
You will get the notification like this
Notification with action buttons
curl -XPOST -H 'Content-Type: application/json' http://localhost:3000/send -d ' { "notification": { "title": "Push Notification", "body": "Hey Dude!", "icon": "icon.png", "actions": [ { "action": "ok", "title": "Ok", "url": "https://www.appzcoder.com/" }, { "action": "cancel", "title": "Cancel", "url": "https://google.com/" } ] } } '