LC8 - Stumbling into JSON

Richard Gaskin ambassador at fourthworld.com
Tue Jun 14 11:52:47 EDT 2016


Graham Samuel wrote:

 > My query about ‘result’ and ‘value’ wasn’t about arrays as such,
 > it was about the use of those particular labels in that context
 > - the answer is (I suppose) that one has to know the spec of the
 > JSON that is being used in order  to know what the JSON output
 > looks like (and indeed what the function does).

Like learning LiveCode's API, any good REST API will be well documented 
with examples to help the developer understand what the call expects to 
receive and what it will return.


Devin Asay wrote:

 > They are more properly called web services, and are accessible
 > through published web service APIs. There are some web sites that
 > act as “clearing houses” of sorts to publicize these APIs. See,
 > for example:
 >
 > http://www.programmableweb.com
 > http://apis.io
 >
 > There is a fellow named Kin Lane who publishesa great site all about
 > web APIs:
 >
 > http://apievangelist.com
 >
 > I created a lesson outline for my class on this topic:
 >
 > http://livecode.byu.edu/internet/webServicesIntro.php
 >
 > As you’ll see it’s a whole new world of functionality, and so simple
 > to access through LiveCode, using GET and PUT requests.

...and with LC Server also easy to provide.

When designing a REST API I've found Vinay Sahni's "Best Practices for 
Designing a Pragmatic RESTful API" the best one-stop-shopping for good, 
clear ideas:
http://www.vinaysahni.com/best-practices-for-a-pragmatic-restful-api

Andre Garzia's revSpark library helps with implementing good REST APIs:
http://andregarzia.com/pages/en/revspark/

Extra bonus points:  if both your client and server are written in 
LiveCode, you can bypass JSON and use LSON instead, LiveCode's own 
native array serialization provided by arrayEncode and arrayDecode. 
These binary data streams can even be compressed with LC's built-in 
compress function for faster transport.

Super-easy to work with in LC, and being as native to LC as JSON is to 
JavaScript you'll be hard-pressed to find a data format more efficient 
when sharing array data between LC clients and LC servers.

In fact, if you have an API that may sometimes deliver to LC-based 
clients and sometimes to Web clients, you can take a tip from Vinay's 
article and have JSON as the default but allow the requesting URL to end 
with ".json" to specify JSON as the delivery format.

-- 
  Richard Gaskin
  Fourth World Systems
  Software Design and Development for the Desktop, Mobile, and the Web
  ____________________________________________________________________
  Ambassador at FourthWorld.com                http://www.FourthWorld.com




More information about the Use-livecode mailing list