Skip to content

Instantly share code, notes, and snippets.

@matzew
Last active December 15, 2015 04:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matzew/2da6fc349a4aaf629bce to your computer and use it in GitHub Desktop.
Save matzew/2da6fc349a4aaf629bce to your computer and use it in GitHub Desktop.
REGISTRY REST API

WARNING: YES... AUTH, SERVER-KEY headers etc are not included, YET.....

For registering a push application (see shared gist details), I want the following REST API for adding that "generic" push app:

Push App Registration

Submit a HTTP POST against /registry/applications/, with a body like this (yes... API key headers are missing):

{
  "description":"just a test",
  "name":"TestApp"
}

A cURL example looks like:

curl -v -H "Accept: application/json" -H "Content-type: application/json" -X POST -d '{"description":"just a test", "name":"TestApp"}' http://localhost:8080/registry/applications

The 201 response looks like:

{"id":"a325b21f6c744df185b8bea25d56045c"}

Add mobile app for the Push App:

Apple iOS applications

Submit a HTTP POST against /registry/applications/a325b21f6c744df185b8bea25d56045c/iOS, with a body like:

{
  "appleId":"com.yo.ur.app",
  "cert":"CERT_UPLOAD_VAL",
  "passphrase": "top-secret"
}

The 201 response looks like:

{"id":"ec24e09537bf4ef5b5db02bbb3b9d0e5"}

(Google) Android applications

Submit a HTTP POST against /registry/applications/a325b21f6c744df185b8bea25d56045c/android, with a body like:

{
  "google-api-key": "dsdsaadsadsdasadsdsa"
}

The 201 response looks like:

{"id":"dcd7a464403447ee9f4ea9bcbd06f849"}

(Mobile) Web applications

Submit a HTTP POST against /registry/applications/a325b21f6c744df185b8bea25d56045c/web, with a body like:

{
  "channels":[
    "com.news.feed",
    "notifications"
  ]
}

The 201 response looks like:

{"id":"a943b58c80c0402790ea98ebb83a4110"}

Unique Channels, per Web App

To avoid that more apps are using the above notifications (or com.news.feed) channel, we should prefix the desired channels with the ID for the (mobile) web. The (server) internal name would be like:

  • a943b58c80c0402790ea98ebb83a4110.notifications
  • a943b58c80c0402790ea98ebb83a4110.com.news.feed

Of course... the Web View needs to have it's ID ...

When the notifier API does the following:

notifier.sub("com.news.feed"......);

This translates internally to something like ID+channelname. e.g.:

notifier.sub("a943b58c80c0402790ea98ebb83a4110.com.news.feed"......);

Device/Installation registration

native mobile OS

Note: The tokens are submitted from the CLIENT APP - on the device

Information we have on the DEVICE:

  • device token (or registrationID, how it's called in Android)
  • the APP ID / package namespace

Things we DO NOT know:

  • Push-APP ID (the logical construct on the server)
  • Mobile APP ID (the logical construct on the server)

If we use the URL from below, the client SDK needs to submit these things.....

Submit a HTTP POST against /registry/device/PUSH-APP-ID/MOBILE-APP-ID, with a body like:

{
  "token": "blah",
  "os": "Android"
}

HOWEVER.... IMO there is a slight risk using the IDs here, on the URL.... Perhaps we should submit them, from the device, as a header ? (and require TLS?)

X-AG-PUSHAPP: 1234
X-AG-MOBILE: 456454

with those header, now submit a HTTP POST against /registry/device/, with a body like:

{
  "token": "blah",
  "os": "Android"
}

On a successful "registration", we do get a 201 response.....

Mobile Web

There is no real concept of an installation, but you can count connected clients.

TODO: Need to find a way to give a unique ID for a (mobile) web client, regardless of its connections to the channels...

Convenience (UBER) API

This allows to register one PushApp, with a batch of mobile apps (several paid, free etc versions)

Submit a HTTP POST against /registry/applications/, with a body like this

{
  name: "My Content Sharing app",
  description: "A never been there app, to share content",
  // add two iOS apps (paid and free)
  ios: {
    [
      {apple-ID: "com.my.paid",
      cert: "certval1",
        passphrase: "passphrase1"},

      {apple-ID: "com.my.free",
      cert: "certval2",
      passphrase: "passphrase2"}
   ]         
  },
  // add two Android apps (paid and free)
  android: {
    [
     {"google-api-key": "key1"},
     {"google-api-key": "key2"}
   ]  
  },
  // add one web app, with one channel
  web: {
    "channels":[
      "my-notifications"
    ]
  }
}

For this convenience API the 201 Response could look like:

{
  "id":"PushAppKey"
  "apps":[
     {"iOS-ID":"adda213213"},
     {"iOS-ID":"24da213213"},
     {"android-ID":"454dda213213"},
     {"android-ID":"g52234213213"},
     {"web-ID":"og2352234213213"},
  ]
}

VERT.X SERVER HOOKS:

Here are the routes for that....:

// register Push Applications:
rm.post("/registry/applications", new Handler<HttpServerRequest>() {
  public void handle(final HttpServerRequest request) {
    request.dataHandler(new Handler<Buffer>() {
      public void handle(Buffer buffer) {
        PushApplication pushApp = (PushApplication) Json.decodeValue(buffer.toString(), PushApplicationImpl.class);
        // store it.......

        JsonObject response = new JsonObject().putString("id", pushApp.getApplicationKey());
        request.response.end(response.toString());
      }
    });
  }
});

// Register Mobile Apps:
rm.post("/registry/applications/:key/:variant", new Handler<HttpServerRequest>() {
  public void handle(final HttpServerRequest request) {
......
@kborchers
Copy link

I like the idea of using headers for the IDs rather than on the URL.

👍

@sebastienblanc
Copy link

Good work !
Some remarks :

  • How does a web (connected) client retrieve the list of available Channels, could it be just a HTTP GET on /registry/applications/a325b21f6c744df185b8bea25d56045c/web/channels ? Or is this out of scope ?
  • As far as I understand, the unique ID is for a Web Application and not a connected Web client , right ?
    ** If we need a point to point channel, will it be the same API call, returning an unique ID for the client ? Or will it be another service to register the channel (or flag) ?
    ** On the opposite, imagine we want to broadcast a message to all the Web Applications (i.e: an Editor who wants to promote a new product to all his clients no matter the app they are using) is the idea that we send a message to each Web App or do we want the concept of Uber Channel ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment