REAST API help

Bringing the internet highway into your project? Building FTP, HTTP, email, chat or other client solutions?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
ckelly5430
Posts: 15
Joined: Wed Sep 11, 2013 3:44 pm

REAST API help

Post by ckelly5430 » Thu Feb 06, 2014 5:07 pm

Hi Livecoders,

I’ve subscribed to a SMS text message service that uses a simple REST or SOAP API

I’ve built an application in Delphi that use SOAP/ActiveX to dispatch the message and read the response but would really like to use the REST API in a Livecode desktop application, I’m new to Livecode and struggling to understand where to start with this simple task.

Could somebody be kind enough to write me some pseudo code and point me in the right direction: the key elements are:

URL: <THE_URL_TO_SEND_TO>

Method: POST

Authentication: Basic / Session

Example request:

<?xml version='1.0' encoding='UTF-8'?>
<messages>
<accountreference>MYACCOUNTDETAILS</accountreference>
<message>
<to>44xxxxxxxxxx</to>
<body>Hello World!</body>
</message>
</messages>

Response: Content Type: application/xml HTTP Status Code: 200

Thanks in advance.

I did originally post this message in the "complete beginners" forum but now think it may be better posted here. - apologies for double postings as this has now become quite pressing

Col.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10043
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: REAST API help

Post by FourthWorld » Thu Feb 06, 2014 5:12 pm

Moderation note: A duplicate of this thread was formerly in the "Complete Beginners" section, since deleted so those wanting to reply to this request can know where to do so. Going forward please make only one thread for a given topic, per the Forum Guidelines at http://forums.runrev.com/viewtopic.php?f=4&t=18885. Thanks.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10043
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: REAST API help

Post by FourthWorld » Thu Feb 06, 2014 5:15 pm

See the POST command in the Dictionary. For creating the XML data that gets sent, you may also want to filter the Dictionary to find the many commands available via LiveCode's XML external, included in the LiveCode package.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

bangkok
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 937
Joined: Fri Aug 15, 2008 7:15 am

Re: REAST API help

Post by bangkok » Thu Feb 06, 2014 5:19 pm

OK. I see 3 steps.

1 - the header
It's necessary to create a special header.
Put it into a variable (or a field) and then

Code: Select all

  libURLSetCustomHTTPHeaders field "MyHeader"
2 - the query
Here it's very simple, a simple POST command

Code: Select all

post tMyQuery to url "http://www.cccc.com/webservice/CAdxSubProgramXml"
put it into tResult
3 - the server will send back XML data, right ?
Here, you'll need some XML commands.
I advise the stack from Trevor DeVore of Blue Mango Learning Systems.

ckelly5430
Posts: 15
Joined: Wed Sep 11, 2013 3:44 pm

Re: REAST API help

Post by ckelly5430 » Thu Feb 06, 2014 5:49 pm

Thanks for your response - what do I need to put into the "libURLSetCustomHTTPHeaders" ?

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10043
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: REAST API help

Post by FourthWorld » Thu Feb 06, 2014 6:05 pm

Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

bangkok
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 937
Joined: Fri Aug 15, 2008 7:15 am

Re: REAST API help

Post by bangkok » Thu Feb 06, 2014 11:04 pm

ckelly5430 wrote:Thanks for your response - what do I need to put into the "libURLSetCustomHTTPHeaders" ?
Here is a header I use for a webservice.

Code: Select all

POST /adxwsvc/services/CAdxSubProgramXml HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: text/xml;charset=UTF-8
SOAPAction: ""
Content-Length: 1871
Host: www.www.www.ww:18980
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)
-> you have to get the length of your POST query, and copy it into the header (line content-length).

Post Reply