# Push API — Progressive Web Apps: Offline, Installable Web Apps

Source: https://www.skillbyai.com/hi/pwa/pwa-push-api

> Users को Push API से subscribe करें, subscription अपने server को भेजें और service worker में push events संभालें।

## Push Message Delivery

**Push API** आपके server को push service के माध्यम से users को messages भेजने में सक्षम बनाता है। Messages तब भी arrive होते हैं जब app बंद हो, और service worker उन्हें handle करता है।

## Push messages को subscribe करें

Push को subscribe करें और server को endpoint भेजें।

```javascript
navigator.serviceWorker.ready.then(reg => {
  reg.pushManager.subscribe({
    userVisibleOnly: true,
    applicationServerKey: urlBase64ToUint8Array(PUBLIC_KEY)
  }).then(subscription => {
    console.log('Subscribed:', subscription.endpoint);
    // Send subscription to server
    fetch('/subscribe', {
      method: 'POST',
      body: JSON.stringify(subscription)
    });
  });
});
```

Output:

```
App subscribed to push messages; server can now send messages to user.
```
