Upgrade Your Apps to Work with Our New Serverless SDKPosted by Matt Billock on Mar 02, 2017
This post is a quick guide to upgrading your existing Backand-powered applications to work with the new Backand Serverless SDK we announced a couple of weeks ago. We’ll cover the changes made in the SDK, and explore the steps you need to take to get your Backand application up and running with the new API.
We’ve made a number of changes in our new SDK that make developing against Backand faster than ever. Here’s a brief overview of what changed:
- Streamlined authentication, making it easier for you to authenticate your users.
- Improved the process for registering with – and signing in via – social media providers with the addition of new SDK methods.
- Greatly improved the method in which you interact with Backand objects. Gone are the days of needing to manually construct a URL – simply specify the object name as part of a clearly-named function call to the API, and we handle the complexity for you.
- We have also streamlined our response data, allowing you to work with the results of calls to your Backand back-end in a more straightforward manner.
And on top of all this, we continue to offer the same secure, scalable, and responsive backend-as-a-service that we always have!
Converting old app code to the Serverless SDK
Next, let’s look at what steps are needed to change a Backand application to work with the new SDK. For reference, we are basing this code off of our base Ionic starter app – see it on the Ionic marketplace at https://market.ionic.io/starters/backand-simple.
Step 1: Add new SDK to bower.json
First, you’ll need to add the new SDK to your bower file.
Step 2: Update Script includes in index.html to include the new SDK.
Start with removing the old SDK by commenting out – or deleting – the following line:
Then, replace it with the new SDK links:
Or, use the CDN files:
Note: You may want to check your dependencies directory for any lingering versions of the old Backand SDK – this can cause cache issues due to competing HTTP Interceptors. Simply remove the old folder from the appropriate directory in your project.
Step 3: Update the user authentication method
User authentication is largely unchanged, with a few notes below:
- If you have previously disabled anonymous auth in your app, you can re-enable it using Backand.useAnonymousAuth(). This value defaults to true, so if you do not modify the default value you do not need to make any changes.
- We’ve added new social media authentication functions: socialSignin, and socialSignup. Please note that while some of the examples in our github repos – and some of our documentation – used socialSignUp to refer to the specified function in the Backand SDK, this is no longer valid – the “up” will not be capitalized in the new SDK.
Step 4: Update the method used to detect unauthorized users
The getToken() method has been expanded, to use a promise. Originally this method would return undefined when a user was unauthorized, but this functionality can now be managed via the promise method. In the new SDK, the getToken() method is not as prominent as it was in previous versions, and you are likely to not need it as you work on your app.
Step 5: Change $http usage to use the Backand SDK REST methods:
The Serverless SDK features wrapper methods that can be used in place of the direct HTTP calls used in the previous method. Here’s a quick comparison of the old SDK’s HTTP communications, as compared to the new function-based Serverless SDK:
Step 6: Update data result usage
The old SDK would use code similar to the following when handling responses from Back& API calls:
The new SDK does not store the results in a nested data member, but rather in a root data element. The old SDK stored the response contents in a root property, meaning that the actual data was a subset of this
data property – hence the use of
result.data.data in the old SDK. With the new SDK, you no longer need the extra level of disambiguation, and can store the data in your application’s object with the following code:
In this post, we covered the Backand Serverless SDK. We touched briefly on the features the new SDK has to offer and walked through the process necessary to convert an existing Backand-powered app to the new API. Most importantly, though, is that we built this SDK based on your feedback, and we want more! Connect with us via social media (Twitter, Facebook), or on StackOverflow, or even directly via comments on our Git repos and contacting customer support – we’d love to incorporate your thoughts and suggestions into the next version.
Don’t have a Backand account? You can get one for free