You will need to create a web service client when you want to access any third party web service. All you need is the system function #http which takes 3 parameters, URL, http-method and an optional body. The body may be required for http-method POST and may need to be enclosed in a JSON, XML or any other format as required by the API.
str host="http://maps.googleapis.com/maps/api/geocode/json?address=American+Embassy,+Dhaka,+Bangladesh" str response=#http(host,"GET","")
The raw response from the host may be encoded in a JSON, XML or any other format as defined by the API. You will need to extract the relevant data from the raw response. Try the method ca_test_client.method for an example.
To publish a RESTful web service in DreamApps, you will need to define
While naming the resources, please follow the following convention to avoid confusion.
Query format - name_q.json
Response format - name_r.json
Method - name.method
DreamApps doesn't allow any web service without authentication. So, all calls to DreamApps web services need a sessionid which is obtained by a call to authentication web service zx_auth which returns a sessionid on successful authentication.
Try the method ca_test_server.method for an example of using the web service ca_test, which is implemented by ca_test_q.json, ca_test_r.json and ca_test.method.
There is a single system function #json to manipulate JSONs in DreamApps. It can take up to 3 parameters.
Creating a JSON needs just one parameter and can have two formats.
str s=#json(file "filename.json")
or,
str s=#json("valid-text-string")
Extracting a field-value from a JSON needs 2 parameters.
str s=#json(json-string-name, key)
Inserting a field-value into a JSON needs 3 parameters.
str s=#json(json-string-name, key, field-value)
See the method ca_test_server.method for examples of #json usage.
Here is an example. Run something like the followings:
str host="http://ig.dreamapps.com/da/ws" set s=#json(file "zx_auth_q.json") set s=#json(s,"businessid","630006") set s=#json(s,"username","asok@dreamapps.com") set s=#json(s,"password","go") set s=#http(host,"POST",s) print s