Page 1 of 2
working with REST services
Posted: Wed Apr 18, 2012 9:01 am
by tzenobite
hi
first of all, i have to explain why i'm asking this here: i've to write a sort of client for a website, the guy which has made the website, the databases, the REST services etc is gone from the web agency and the other guy who's still there isnt' happy (at all) for it, he says to me he don't know a lot about the website and so on, and can't (won't, actually) help me
so, i have to deal with this: a REST service to get information and data from the website
the guy on the phone told me a lot about javascript, JSON serialization and many more, but he don't give me a single line of useful code
i'm successfully grabbing data using GET command but i can't figure out how to deal with these two actions:
read the account status
Code: Select all
Url: http://www.eroxe.it/eroxeservice/eroxeservice/accounts/
HTTP Method: POST
The following is an example request Json body:
{
"Username":"String content",
"Password":"String content"
}
The following is an example response Json body:
{
"Valido":true,
"Scadenza":"String content"
}
http://www.eroxe.it/eroxeservice/eroxes ... bbonamento
get a file from the database (the service previously checks if the user has a valid subscription)
Code: Select all
Url: http://www.eroxe.it/eroxeservice/eroxeservice/novels/{ID}
HTTP Method: POST
The following is an example request Json body:
{
"Username":"String content",
"Password":"String content"
}
The following is an example response Json body:
{
"Codice":2147483647,
"Titolo":"String content",
"Testo":"String content",
"Genere":"String content",
"Autore":"String content",
"DataInserimento":"String content"
}
http://www.eroxe.it/eroxeservice/eroxes ... ccontoByID
i tried to put the json request body code in a variable and post it to the website in the usual way (post variable to url "http://...") but it doesn't work and the website don't return anything
the website guy told me something about data serialization and javascript, the android app made from his ex coworker works this way to get a novel from the site:
- inside the android app: result =
Code: Select all
service.GetRaccontoByCodice(codice, new EroxeCredentials(username, password));
- the object at the second parameter is:
Code: Select all
public class EroxeCredentials
{
public string Username { get; set; }
public string Password { get; set; }
}
how to do this with lc?
many thanks to all and many excuses for my english

Re: working with REST services
Posted: Wed Apr 18, 2012 5:22 pm
by mwieder
Looks like web services on the server. If so, then my libSOAP stack on revOnline may be of some help to you. It's set to use xml rather than json, but converting shouldn't be a huge task. Is there a wsdl document available somewhere? That's the key to using these services, but from the looks of the urls you posted (they're private, so can't get in) the help for the functions is available online.
Re: working with REST services
Posted: Wed Apr 18, 2012 5:29 pm
by tzenobite
if you cant read it, the hel page for the second service says that:
Code: Select all
Reference for http://www.eroxe.it/eroxeservice/eroxeservice/novels/{ID}
Url: http://www.eroxe.it/eroxeservice/eroxeservice/novels/{ID}
HTTP Method: POST
Message direction Format Body
Request Xml Example,Schema
Request Json Example
Response Xml Example,Schema
Response Json Example
The following is an example request Xml body:
<EroxeCredentials xmlns="http://schemas.datacontract.org/2004/07/Eroxe">
<Username>String content</Username>
<Password>String content</Password>
</EroxeCredentials>
The following is an example request Json body:
{
"Username":"String content",
"Password":"String content"
}
The following is an example response Xml body:
<RaccontoDTO xmlns="http://www.eroxe.it/eroxeservice/">
<Codice>2147483647</Codice>
<Titolo>String content</Titolo>
<Testo>String content</Testo>
<Genere>String content</Genere>
<Autore>String content</Autore>
<DataInserimento>String content</DataInserimento>
</RaccontoDTO>
The following is an example response Json body:
{
"Codice":2147483647,
"Titolo":"String content",
"Testo":"String content",
"Genere":"String content",
"Autore":"String content",
"DataInserimento":"String content"
}
The following is the request Xml Schema:
<xs:schema xmlns:tns="http://schemas.datacontract.org/2004/07/Eroxe" elementFormDefault="qualified" targetNamespace="http://schemas.datacontract.org/2004/07/Eroxe" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="EroxeCredentials">
<xs:sequence>
<xs:element minOccurs="0" name="Username" nillable="true" type="xs:string" />
<xs:element minOccurs="0" name="Password" nillable="true" type="xs:string" />
</xs:sequence>
</xs:complexType>
<xs:element name="EroxeCredentials" nillable="true" type="tns:EroxeCredentials" />
</xs:schema>
Additional request Xml Schemas:
<xs:schema xmlns:tns="http://schemas.microsoft.com/2003/10/Serialization/" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://schemas.microsoft.com/2003/10/Serialization/" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="anyType" nillable="true" type="xs:anyType" />
<xs:element name="anyURI" nillable="true" type="xs:anyURI" />
<xs:element name="base64Binary" nillable="true" type="xs:base64Binary" />
<xs:element name="boolean" nillable="true" type="xs:boolean" />
<xs:element name="byte" nillable="true" type="xs:byte" />
<xs:element name="dateTime" nillable="true" type="xs:dateTime" />
<xs:element name="decimal" nillable="true" type="xs:decimal" />
<xs:element name="double" nillable="true" type="xs:double" />
<xs:element name="float" nillable="true" type="xs:float" />
<xs:element name="int" nillable="true" type="xs:int" />
<xs:element name="long" nillable="true" type="xs:long" />
<xs:element name="QName" nillable="true" type="xs:QName" />
<xs:element name="short" nillable="true" type="xs:short" />
<xs:element name="string" nillable="true" type="xs:string" />
<xs:element name="unsignedByte" nillable="true" type="xs:unsignedByte" />
<xs:element name="unsignedInt" nillable="true" type="xs:unsignedInt" />
<xs:element name="unsignedLong" nillable="true" type="xs:unsignedLong" />
<xs:element name="unsignedShort" nillable="true" type="xs:unsignedShort" />
<xs:element name="char" nillable="true" type="tns:char" />
<xs:simpleType name="char">
<xs:restriction base="xs:int" />
</xs:simpleType>
<xs:element name="duration" nillable="true" type="tns:duration" />
<xs:simpleType name="duration">
<xs:restriction base="xs:duration">
<xs:pattern value="\-?P(\d*D)?(T(\d*H)?(\d*M)?(\d*(\.\d*)?S)?)?" />
<xs:minInclusive value="-P10675199DT2H48M5.4775808S" />
<xs:maxInclusive value="P10675199DT2H48M5.4775807S" />
</xs:restriction>
</xs:simpleType>
<xs:element name="guid" nillable="true" type="tns:guid" />
<xs:simpleType name="guid">
<xs:restriction base="xs:string">
<xs:pattern value="[\da-fA-F]{8}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{12}" />
</xs:restriction>
</xs:simpleType>
<xs:attribute name="FactoryType" type="xs:QName" />
<xs:attribute name="Id" type="xs:ID" />
<xs:attribute name="Ref" type="xs:IDREF" />
</xs:schema>
<xs:schema targetNamespace="http://www.w3.org/2001/XMLSchema" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="schema">
<xs:complexType />
</xs:element>
</xs:schema>
The following is the response Xml Schema:
<xs:schema xmlns:tns="http://www.eroxe.it/eroxeservice/" elementFormDefault="qualified" targetNamespace="http://www.eroxe.it/eroxeservice/" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="RaccontoDTO">
<xs:sequence>
<xs:element minOccurs="0" name="Codice" type="xs:int" />
<xs:element minOccurs="0" name="Titolo" nillable="true" type="xs:string" />
<xs:element minOccurs="0" name="Testo" nillable="true" type="xs:string" />
<xs:element minOccurs="0" name="Genere" nillable="true" type="xs:string" />
<xs:element minOccurs="0" name="Autore" nillable="true" type="xs:string" />
<xs:element minOccurs="0" name="DataInserimento" nillable="true" type="xs:string" />
</xs:sequence>
</xs:complexType>
<xs:element name="RaccontoDTO" nillable="true" type="tns:RaccontoDTO" />
</xs:schema>
Additional response Xml Schemas:
<xs:schema xmlns:tns="http://schemas.microsoft.com/2003/10/Serialization/" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://schemas.microsoft.com/2003/10/Serialization/" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="anyType" nillable="true" type="xs:anyType" />
<xs:element name="anyURI" nillable="true" type="xs:anyURI" />
<xs:element name="base64Binary" nillable="true" type="xs:base64Binary" />
<xs:element name="boolean" nillable="true" type="xs:boolean" />
<xs:element name="byte" nillable="true" type="xs:byte" />
<xs:element name="dateTime" nillable="true" type="xs:dateTime" />
<xs:element name="decimal" nillable="true" type="xs:decimal" />
<xs:element name="double" nillable="true" type="xs:double" />
<xs:element name="float" nillable="true" type="xs:float" />
<xs:element name="int" nillable="true" type="xs:int" />
<xs:element name="long" nillable="true" type="xs:long" />
<xs:element name="QName" nillable="true" type="xs:QName" />
<xs:element name="short" nillable="true" type="xs:short" />
<xs:element name="string" nillable="true" type="xs:string" />
<xs:element name="unsignedByte" nillable="true" type="xs:unsignedByte" />
<xs:element name="unsignedInt" nillable="true" type="xs:unsignedInt" />
<xs:element name="unsignedLong" nillable="true" type="xs:unsignedLong" />
<xs:element name="unsignedShort" nillable="true" type="xs:unsignedShort" />
<xs:element name="char" nillable="true" type="tns:char" />
<xs:simpleType name="char">
<xs:restriction base="xs:int" />
</xs:simpleType>
<xs:element name="duration" nillable="true" type="tns:duration" />
<xs:simpleType name="duration">
<xs:restriction base="xs:duration">
<xs:pattern value="\-?P(\d*D)?(T(\d*H)?(\d*M)?(\d*(\.\d*)?S)?)?" />
<xs:minInclusive value="-P10675199DT2H48M5.4775808S" />
<xs:maxInclusive value="P10675199DT2H48M5.4775807S" />
</xs:restriction>
</xs:simpleType>
<xs:element name="guid" nillable="true" type="tns:guid" />
<xs:simpleType name="guid">
<xs:restriction base="xs:string">
<xs:pattern value="[\da-fA-F]{8}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{12}" />
</xs:restriction>
</xs:simpleType>
<xs:attribute name="FactoryType" type="xs:QName" />
<xs:attribute name="Id" type="xs:ID" />
<xs:attribute name="Ref" type="xs:IDREF" />
</xs:schema>
<xs:schema targetNamespace="http://www.w3.org/2001/XMLSchema" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="schema">
<xs:complexType />
</xs:element>
</xs:schema>
Re: working with REST services
Posted: Wed Apr 18, 2012 6:07 pm
by bangkok
mwieder wrote:Looks like web services on the server. If so, then my libSOAP stack on revOnline may be of some help to you. It's set to use xml rather than json, but converting shouldn't be a huge task. Is there a wsdl document available somewhere? That's the key to using these services, but from the looks of the urls you posted (they're private, so can't get in) the help for the functions is available online.
hello mark,
i'm going to use a private webservice, using SOAP. It's totally new for me.
I found your library.
I have one (silly) question ?
Why do we need... a library ?
SOAP is nothing else than a XML envelopp to handle XML data, correct ?
So :
-if i know the webservice, it means i don't have to use a wsdl
-then i can "emulate" the SOAP envelopp, fill my XML data inside
-and POST the document directly to my webservice
... is it correct ?
Re: working with REST services
Posted: Wed Apr 18, 2012 6:21 pm
by mwieder
That's correct. If you can get the proper header formats and/or authentication headers set up properly and you can package up the xml data and post it, then you're good to go.
The library helps you do all this without having to relearn how to do it each time (I got tired of having to start from scratch for each new service) and also provides functions that can automatically generate the templates for you from a wsdl document. It also encompasses a lot of what I reverse-engineered by examining Wireshark network traffic to get the formatting down.
I've got a new version of the library now and if they ever fix revOnline I'll post the new one.
Re: working with REST services
Posted: Wed Apr 18, 2012 6:28 pm
by bangkok
Great. Thanks for your answer.
I'm looking forward to test your new version.
Re: working with REST services
Posted: Wed Apr 18, 2012 8:44 pm
by tzenobite
since i have to deal with only one server and have to do only two tasks that needs, maybe i need only how to pack up the xml requests in a string, just like bangkok says?
Re: working with REST services
Posted: Thu Apr 19, 2012 7:23 pm
by mwieder
Attempting to attach the libSOAP library as a zipped file.
Update: seems to have worked. Note that this is for xml, not for json. (maybe json someday).
Re: working with REST services
Posted: Fri Apr 20, 2012 8:52 pm
by tzenobite
this code will work with your stack?
Code: Select all
<xs:schema xmlns:tns="http://schemas.datacontract.org/2004/07/Eroxe" elementFormDefault="qualified" targetNamespace="http://schemas.datacontract.org/2004/07/Eroxe" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="EroxeCredentials">
<xs:sequence>
<xs:element minOccurs="0" name="Username" nillable="true" type="xs:string" />
<xs:element minOccurs="0" name="Password" nillable="true" type="xs:string" />
</xs:sequence>
</xs:complexType>
<xs:element name="EroxeCredentials" nillable="true" type="tns:EroxeCredentials" />
</xs:schema>
what i have to do if i need your library into a iOS deployment?
Re: working with REST services
Posted: Fri Apr 20, 2012 9:12 pm
by mwieder
this code will work with your stack?
I don't see any problems with that.
what i have to do if i need your library into a iOS deployment?
No idea. But everything's based on http, so as long as libURL is available you should be able to do the http post statement.
Re: working with REST services
Posted: Sat Apr 21, 2012 2:00 pm
by tzenobite
i don't want to bother you all, but i'm stuck here
i'm very sorry but i need to get the solution from someone of you... earlier today the webmaster wrote me that all i have to know in oprder to work with the service is here:
Code: Select all
This page describes the service operations at this endpoint.
Uri Method Description
/accounts/ POST Service at http://www.eroxe.it/eroxeservice/eroxeservice/accounts/
/genres/ GET Service at http://www.eroxe.it/eroxeservice/eroxeservice/genres/
/novels/ GET Service at http://www.eroxe.it/eroxeservice/eroxeservice/novels/?title={TITLE}&author={AUTHOR}&genre={GENRE}&page={PAGE}&pageSize={PAGESIZE}
/novels/{id} POST Service at http://www.eroxe.it/eroxeservice/eroxeservice/novels/{ID}
/novels/last GET Service at http://www.eroxe.it/eroxeservice/eroxeservice/novels/last
/novels/oftheday/ GET Service at http://www.eroxe.it/eroxeservice/eroxeservice/novels/oftheday/?onlyHeader={ONLYHEADER}
/offers/ GET Service at http://www.eroxe.it/eroxeservice/eroxeservice/offers/
http://www.eroxe.it/eroxeservice/eroxeservice/help
and here i have only the code i've already post here before
the guy wrote me also that i need to use javascript or "some httpclient" object in order to work with the service
i can't understand absolutely nothing of all of this, so i'm asking you if someone will be kind enough to help me with the code i will need to work wiht these REST services within a ios app made with livecode
i'm in your hands, as we say here in italy

Re: working with REST services
Posted: Mon Apr 23, 2012 7:59 pm
by mwieder
Once again, there's not enough data here to work with. It looks like you don't have SOAP services, but a simple RESTful interface. The urls you post don't work because you need authentication to get into the protected site. So, based on what information you've supplied...
You might try something like this:
Code: Select all
-- usage:
-- get PostData("novels", "name", "password")
-- get PostData("novels", "name", "password", 1234)
function PostData pUrl, pUsername, pPassword, pID
local myData
-- need to add a header here
set the httpHeaders to "X-POST_DATA_FORMAT: xml"
put "<request>" into myData
if pContent is not empty then
put "<EroxeCredentials>" after myData
put "<Username>" & pUsername & "</Username>" after myData
put "<Password>" & pPassword & "</Password>" after myData
put "</EroxeCredentials>" after myData
end if
-- handle the "novels/{ID} case
if pID is not empty then
put "/" & pID after pUrl
end if
put "</request>" after myData
-- post the data to the site
-- NOTE that a post is a blocking command, so this
-- will wait here until a response is received.
post myData to url ("http://www.eroxe.it/eroxeservice/eroxeservice/" & pUrl)
return it
end PostData
Re: working with REST services
Posted: Fri Apr 27, 2012 8:49 pm
by tzenobite
ufff, it doesn't work...
i'm going to be very annoying, but i finally got the code from the android app... any chance to get java routines in/within/translated to livecode?

Re: working with REST services
Posted: Sun Apr 29, 2012 10:38 am
by tzenobite
GOT IT!
for anyone else whom may be interested, after all this is how i worked it out:
i've found a strange thing for google chrome, a free add-on called REST console
https://chrome.google.com/webstore/deta ... phppikmonn
there i played a little with parameters found in the rest reference page, the add-on not only send GET and POST command and shows results but also displays the request body and headers
so when i've successfully POST the right data i got not only the wanted answer but also the data i needed, within livecode i had only to send httpheaders i got in the console and POST the xml request body i've found in the rest help pages to get my stuff
hope this may helps someone else here
...now i'm sure, finally, that the website guy want NOT to help me

Re: working with REST services
Posted: Wed May 02, 2012 2:25 pm
by beugelaar
Hello tzenobite,
I have the same issue. Could you please post the LC code (snippet)?
Thanks in advance!
Erik