Connecting to BAAS from LiveCode
Posted: Fri May 17, 2013 5:08 pm
Wow. If anyone's nervous about dabbling in the world of "Backend As A Service" (http://en.wikipedia.org/wiki/BaaS) systems for data storage, user auth, social integration, Amazon S3, push messaging, geo-location / GPS, sending e-mail and many more goodies besides - don't be. Took me (a silly person and LC newby) less than half an hour to get data flying into & out of StackMob using their REST API and a few LC commands. A compliment to both LC and StackMob.
Setup some HTTP headers in LC:
Accept: application/vnd.stackmob+json; version=0
X-StackMob-API-Key: [ the key given to you by StackMob]
Content-Type: application/json
Specify a URL for what you're trying to do, as per the StackMob docs - in this case to query an item I've called "resident" whose surname contains "Smith"
http://api.stackmob.com/resident?lastname[in]=Smith
And then run the response (JSON) through Monte Goulding's MergJSON to convert it into an LC array for further manipulation if required:
{
"phone_number":"0123456789",
"phone_account":"EA12399900",
"dob":"25/12/68",
"firstname":"Mary",
"lastmoddate":1368805470438,
"lastname":"Smith",
"resident_id":"1476d0ddeb1144a59df01429c42c9188",
"salutation":"Mrs",
"createddate":1368805470438,
"room":1,
"doa":"11/10/12"
}
I've been in touch with the StackMob guys (amongst others, but StackMob were the only ones kind enough to reply) about the possibility of a LiveCode SDK and it's something that has already been discussed, so fingers crossed on that one. Using the REST API is fine but I've a feeling that a native SDK would offer additional functionality (offline sync?) which isn't suited to REST so much.
Cheers,
Steve
Setup some HTTP headers in LC:
Accept: application/vnd.stackmob+json; version=0
X-StackMob-API-Key: [ the key given to you by StackMob]
Content-Type: application/json
Specify a URL for what you're trying to do, as per the StackMob docs - in this case to query an item I've called "resident" whose surname contains "Smith"
http://api.stackmob.com/resident?lastname[in]=Smith
And then run the response (JSON) through Monte Goulding's MergJSON to convert it into an LC array for further manipulation if required:
{
"phone_number":"0123456789",
"phone_account":"EA12399900",
"dob":"25/12/68",
"firstname":"Mary",
"lastmoddate":1368805470438,
"lastname":"Smith",
"resident_id":"1476d0ddeb1144a59df01429c42c9188",
"salutation":"Mrs",
"createddate":1368805470438,
"room":1,
"doa":"11/10/12"
}
I've been in touch with the StackMob guys (amongst others, but StackMob were the only ones kind enough to reply) about the possibility of a LiveCode SDK and it's something that has already been discussed, so fingers crossed on that one. Using the REST API is fine but I've a feeling that a native SDK would offer additional functionality (offline sync?) which isn't suited to REST so much.
Cheers,
Steve