WebAPI/SimplePush: Difference between revisions
No edit summary |
|||
| Line 83: | Line 83: | ||
== Server API == | == Server API == | ||
We will use a RESTful API to interact with the Push Server. | |||
The Push Server URL is returned to the client as a result of calling register(). The <i>pushEndpoint</i> is the URL to the Push Server. | |||
=== Registering with Push Server === | |||
<i>pushEndpoint</i>/register | |||
These query parameters are required with each registration: | |||
* API Key | |||
** TBD | |||
** <i>key</i> is the query parameter name | |||
* pushRequestID | |||
** <i>pushRequestID</i> is the query parameter name. | |||
** The value of pushRequestID must be the result returned to the client as a result of calling register(). | |||
Example: | |||
<pre> | <pre> | ||
GET http://push.mozilla.org/register?key=<apikey>&pushRequestID=<pushRequestID> | |||
</pre> | |||
If the request succeeds, the server responds with a 200 OK HTTP status code and the following JSON: | |||
<pre> | |||
// tbd | |||
{ | |||
"result": {} | |||
} | |||
</pre> | |||
=== Un-registering with Push Server === | |||
<i>pushEndpoint</i>/unregister | |||
These query parameters are required with each un-registration: | |||
* API Key | |||
** TBD | |||
** <i>key</i> is the query parameter name | |||
* pushRequestID | |||
** <i>pushRequestID</i> is the query parameter name. | |||
** The value of pushRequestID must be the result returned to the client as a result of calling register(). | |||
Example: | |||
<pre> | |||
GET http://push.mozilla.org/unregister?key=<apikey>&pushRequestID=<pushRequestID> | |||
</pre> | |||
If the request succeeds, the server responds with a 200 OK HTTP status code and the following JSON: | |||
<pre> | |||
// tbd | |||
{ | |||
"result": {} | |||
} | |||
</pre> | |||
=== Notify Push Server of a new version === | |||
<i>pushEndpoint</i>/update | |||
These query parameters are required with each un-registration: | |||
* API Key | |||
** TBD | |||
** <i>key</i> is the query parameter name | |||
* pushRequestID | |||
** <i>pushRequestID</i> is the query parameter name. | |||
** The value of pushRequestID must be the result returned to the client as a result of calling register(). | |||
** <i>version</i> is the query parameter name. | |||
** The value of version is the most current version number of the object referenced by pushRequestID | |||
Example: | |||
<pre> | |||
GET http://push.mozilla.org/unregister?key=<apikey>&pushRequestID=<pushRequestID>&version=<version> | |||
</pre> | |||
If the request succeeds, the server responds with a 200 OK HTTP status code and the following JSON: | |||
<pre> | |||
// tbd | |||
{ | |||
"result": {} | |||
} | |||
</pre> | </pre> | ||
Revision as of 18:45, 14 November 2012
Client Side API
partial interface Navigator {
Push push;
};
interface Push {
// registers to receive push notifications for a given topic
DOMRequest register(DOMString topic);
// registers to stop receiving push notifications for a given topic
DOMRequest unregister(DOMString topic);
// XXXX should be something like [{topic, pushEndpoint, pushRequestID}]
XXXX registered();
};
interface PushRequestEvent : Event {
// this is the URL to which push notifications from the web application
// must be sent to
DOMString pushEndpoint;
// this is the push request id that must be sent to the push server with
// every push notification update
DOMString pushRequestID;
}
interface PushEvent : Event {
// this is topic string used when registering for push notifications
DOMString topic;
// this is the most current version
unsigned long long version;
}
Client Example
// all notifications will be sent to the system message handler.
navigator.mozSetMessageHandler("push", function(e) {
e.target.result.topic == This is the topic that is being observed
e.target.result.version == This is the current version for this topic
});
// to register to listen for a notification,
// you simply call push.register and pass an
// topic of interest:
var req = navigator.push.register("topic");
// success callback
req.onsuccess(e) = function() {
e.target.result.pushEndpoint
e.target.result.pushRequestID
}
req.onerror() = function(e) {}
// to unregister, you simply call..
req = navigator.push.unregister("topic");
req.onsuccess() = function() {}
req.onerror() = function() {}
Server API
We will use a RESTful API to interact with the Push Server.
The Push Server URL is returned to the client as a result of calling register(). The pushEndpoint is the URL to the Push Server.
Registering with Push Server
pushEndpoint/register
These query parameters are required with each registration:
- API Key
- TBD
- key is the query parameter name
- pushRequestID
- pushRequestID is the query parameter name.
- The value of pushRequestID must be the result returned to the client as a result of calling register().
Example:
GET http://push.mozilla.org/register?key=<apikey>&pushRequestID=<pushRequestID>
If the request succeeds, the server responds with a 200 OK HTTP status code and the following JSON:
// tbd
{
"result": {}
}
Un-registering with Push Server
pushEndpoint/unregister
These query parameters are required with each un-registration:
- API Key
- TBD
- key is the query parameter name
- pushRequestID
- pushRequestID is the query parameter name.
- The value of pushRequestID must be the result returned to the client as a result of calling register().
Example:
GET http://push.mozilla.org/unregister?key=<apikey>&pushRequestID=<pushRequestID>
If the request succeeds, the server responds with a 200 OK HTTP status code and the following JSON:
// tbd
{
"result": {}
}
Notify Push Server of a new version
pushEndpoint/update
These query parameters are required with each un-registration:
- API Key
- TBD
- key is the query parameter name
- pushRequestID
- pushRequestID is the query parameter name.
- The value of pushRequestID must be the result returned to the client as a result of calling register().
- version is the query parameter name.
- The value of version is the most current version number of the object referenced by pushRequestID
Example:
GET http://push.mozilla.org/unregister?key=<apikey>&pushRequestID=<pushRequestID>&version=<version>
If the request succeeds, the server responds with a 200 OK HTTP status code and the following JSON:
// tbd
{
"result": {}
}
Simple event flow
+---------------+ +-----------------+ +------------------+
| Browser | | Push Server | | App Server |
+------+--------+ +--------+--------+ +---------+--------+
| register() | |
+---------------------------------->| |
| | |
| ok | |
|<---------------------------------+| |
| | |
| register successful | |
|+------------------------------------------------------------------->|
| | |
| | Update |
| | <-------------------------------+
| | Update |
| | <-------------------------------+
| update | |
|<----------------------------------+ |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |