API and subscription flow reference

API sequence diagrams

Registration:

                           Browser
JS      Service Worker     Vendor           pushitgood.eu        Your webapp
 |            :              :                    |                   :
 |            :              :                    |                   :
 |          GET userDetails                       |                   |
 |------------------------------------------------------------------->|
 |            :              :                    |                   |
 |      200 OK <JWT of user details>              |                   |
 |<-------------------------------------------------------------------|
 |            :              |                    |                   |
 |            :              |                    |                   :
 |  request subscription     |                    |                   :
 |-------------------------->|                    |                   :
 |            :              |                    |                   :
 |<---subscription obj-------|                    |                   :
 |            :              :                    |                   :
 |            :              :                    |                   :
 |      POST /register <subscription+user>        |                   :
 | (contains unique notification vendor endpoint  |                   :
 | required to later send a notification)         |                   :
 |----------------------------------------------->|                   :
 |            :              :                    |  POST webhook     :
 |            :              :                    |------------------>:
 |            :              :                    |                   :

Send notification:

                                            Browser
Your webapp             pushitgood.eu       Vendor(s)       User agent
     |                      |                  :              :
     | POST /notify         |                  :              :
     |--------------------->|                  :              :
     |                      |                  :              :
     |<---notification obj--|                  :              :
     |                      |                  |              :  \
     |                      | WebPush request  |              :  |
     |                      |----------------->|              |  |
     | POST <your-webhook>  |                  | push event   |  |
     |  state="sent|failed" |                  |------------->|  |
     |<---------------------|                  |              |  | Repeated
     |                      |                  |              |  | for
     |                      |                  |              |  | each
     |                      |  POST /ping      |              |  | subscription
     | POST <your-webhook>  |<--------------------------------|  |
     |   state="received"   |                  |              |  |
     |<----push obj---------|                  |              |  /