Marking push notifications as read by making post request from service worker -


i implemented push notifications using service worker. when user clicks on notification want make notification "read" in database. have written api call mark notification "read". how make call service worker. api call in application js file.

i found solution. can directly call our api using "fetch" event service worker. , set "credentials" option in fetch "include", if want include cookies in request

 fetch(url, {                  method: 'post',                 credentials: 'include',                 body: json.stringify({"event_id": <event-id-value>})                 })               .then(function (data) {                 //console.log('request succeeded json response', data);                 })                 .catch(function (error) {                   //console.log('request failed', error);                 }); 

Comments