Todd Appleton - February 10, 2015

ToddAppleton

We’re excited to announce that DreamFactory now supports push notifications using Amazon’s Simple Notification Service (SNS). Notifications can be sent to any endpoint supported by SNS. This includes mobile, email, and HTTP endpoints. 

Read more about the latest DreamFactory software.

Your application can use the DreamFactory REST API to perform many actions related to push such as creating and managing topics, subscribing to topics, and publishing to topics.  On the backend we use the AWS SDK for PHP to provide this functionality. All you have to do is add push as a service on your DSP, much like you would for S3 or other AWS services.  After that you can use the API Docs in your DSP admin console to explore and test out your new push service, or make the REST calls directly from your own app.  

In this blog post we’ll look at how to create a topic, subscribe to the topic with an email endpoint, and publish to the topic, all using the DreamFactory REST API. And lastly we’ll briefly cover how to extend these concepts to mobile push. One thing to note is that we’ll be using version 1.9.0 of the DreamFactory admin console which looks quite different from the previous 1.8.2 version.

Create Your Push Service

Configuring push as a Service on your DSP is simple. Just go to the Services tab and select Create in the upper left. Fill in the Service Info section as shown below and click Create Service.

push1

Get a List of Topics

After creating the service on your DSP, go to the API Docs section of the admin console. Here you can see the available methods and resources for the push service. The list is long, so not all are shown in the screenshot.

push2

You can manage topics, subscriptions, apps, and endpoints from this UI.  When you click ‘Try it out!’ to make an API call it will show you the full request URL and the response.  For example if you do a GET on /push/topic you’ll get back an array of all topics. The empty array in the response means we don’t have any topics yet.

push3

Create a New Topic

Since we have no topics let’s create one by going to POST /push/topic in the API docs. Enter the topic name in the body section.

push4

Click ‘Try it out!’ and the response will contain the newly created topic. Of course you can easily create topics from Amazon’s SNS console as well.

push5

Subscribe to the Topic

Next we’ll use the API Docs to subscribe to our new topic using an email endpoint. Go to POST /push/subscription and set the request body as shown below. You have to use the full name of your topic not just ‘test_topic.’

push6

The response will indicate that the email subscription is pending confirmation.

push7

After confirmation you can do a GET /push/subscription to see the subscription.

push8

Publish to the Topic

Now we can publish to our topic, and the subscription we created will cause the message to be sent to the email endpoint specified when the topic was created.

push9

The response looks like this.

push11

I know it worked because I went to my email and had the following message in my Inbox.

push10

Mobile Push

The more interesting case is when you send push notifications to a mobile endpoint. There’s a lot of information available from AWS and also our API Docs on how to do this. SNS supports several different platforms from Apple, Google, Microsoft, and others. We have an example Android app that shows how to deal with push notifications. The basic steps are as follows. 

  • Create a topic
  • Create an app
  • Create an endpoint on that app
  • Create a subscription for the topic/endpoint
  • Publish to the topic or endpoint

Wrap-Up

For many developers all that is needed is a way for their app to subscribe and publish to topics that already exist. This and other push operations can all be done through the DreamFactory REST API. If you have any questions please visit our forum or contact support

Read more about DreamFactory 1.9:

DreamFactory 1.9.0 Has Shipped!

DreamFactory 1.9.0 Supports Amazon SNS Push Notifications