sohelamin / push-notification

Push Notification

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Push Notification

Push Notification Implementation Using Service Worker & Web Push Protocol

Pre-requisites

Installation

npm install

Usage

  1. Run the Web Push server

    node app.js
    
  2. Serve the client app with any http server

    cd client
    python -m SimpleHTTPServer 8888
    
  3. Visit the client app and allow notification Push Notification

  4. 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 Push Notification

    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/" }
            ]
        }
    }
    '

About

Push Notification


Languages

Language:JavaScript 95.7%Language:HTML 4.3%