|
# retoor <retoor@molodetz.nl>
|
|
|
|
from .._shared import endpoint, field
|
|
|
|
GROUP = {
|
|
"slug": "push",
|
|
"title": "Web Push",
|
|
"intro": """
|
|
# Web Push
|
|
|
|
Browser push notifications via the Web Push protocol. Fetch the public VAPID key, then
|
|
register a `PushSubscription` obtained from the browser's `PushManager`.
|
|
|
|
There is no server-side unsubscribe endpoint: unsubscription is handled entirely in the
|
|
browser by calling `PushManager.unsubscribe()` on the subscription. The server stops delivering
|
|
to a subscription once its push endpoint reports it as gone. These mirror the in-app
|
|
[Notifications](/docs/notifications.html) feed.
|
|
|
|
Every endpoint follows the shared [Conventions & Errors](/docs/conventions.html) (auth, content
|
|
negotiation, pagination, status codes); see [Authentication](/docs/authentication.html) for the
|
|
four ways to sign requests.
|
|
""",
|
|
"endpoints": [
|
|
endpoint(
|
|
id="push-key",
|
|
method="GET",
|
|
path="/push.json",
|
|
title="Get the public key",
|
|
summary="Return the VAPID public key for subscribing.",
|
|
auth="public",
|
|
sample_response={"publicKey": "BASE64_VAPID_KEY"},
|
|
),
|
|
endpoint(
|
|
id="push-register",
|
|
method="POST",
|
|
path="/push.json",
|
|
title="Register a subscription",
|
|
summary="Register a browser push subscription. Sends a welcome notification.",
|
|
auth="user",
|
|
encoding="json",
|
|
interactive=False,
|
|
params=[
|
|
field(
|
|
"endpoint",
|
|
"json",
|
|
"string",
|
|
True,
|
|
"https://fcm.googleapis.com/...",
|
|
"Subscription endpoint URL.",
|
|
),
|
|
field(
|
|
"keys",
|
|
"json",
|
|
"string",
|
|
True,
|
|
'{"p256dh":"...","auth":"..."}',
|
|
"Subscription keys object.",
|
|
),
|
|
],
|
|
notes=[
|
|
'The body must be JSON: `{"endpoint": "...", "keys": {"p256dh": "...", "auth": "..."}}`.'
|
|
],
|
|
sample_response={"registered": True},
|
|
),
|
|
],
|
|
}
|