Editor’s Note: This post is cross-posted with permission from the Clearly Innovative blog, maintained by Aaron Saunders.
This is an introductory post on using StackMob for the backend services of your mobile applications. The StackMob platform helps you build, deploy and scale your backend while making it very easy for you to add push notifications, social integration and more to your apps. Here is a blog posting on why services like StackMob are a value-add for Appcelerator developers.
Why a PaaS for Mobile Developers Makes Sense
Here is my brief outline on the benefits StackMob provides:
- REST Based API
- Custom Code Integration
- Social Media Integration
- Push Notification
- Separation of Production and Staging Environments
In this initial example I have created, there are two simple objects: users and photos. We will expand on the relationship in a later posting, but this is good enough for now.
First you need to go to StackMob and get an account. They are still in beta, but if you indicate that you are trying to integrate with Appcelerator, they will give you priority access.
Create An App
Here we will create our user object. StackMob allows us to specify that the object is a user object and this is how we can log in and out of our application. No trying to roll your own authentication method. It is using xAuth over HTTPS, so you are all set.
Click “Create a Schema” to Add the User Object
Then, enter the appropriate information for your user object .
First you need to initialize the module. I have created a file called
credentials which holds your StackMob credentials and associated application information.
Now with the credentials set, intialize the module.
And finally, create a user object to go along with the object you created in the console.
The client create method is a nice wrapper around a POST of the REST API call to create the user object. The whole objective of the module I created is to cut down on the time spent coding the oAuth API and get straight to doing productive things. The way the module is created, it will take the parameters and return the results as a JSON object
Then, we make an API call through the module to get the list of all of the user(s) we have created in the system.
And, to get a specific user, we can pass in the value for the user name in the GET query.
In Part Two, I’ll cover setting up the Amazon S3 Integration and the uploading of image files to the system.
- Zipped Project Used in the blog posting