Connecting to web services

Without authentication

Contents

In general when connecting to web services, you use the  HTTP API to pull or push the data. The XML or JSON API can be very useful to parse or generate data.

Steps

To Pull data from a web service

  1. Pull data using net.http.get{} or net.http.post{}
  2. Parse the data
  3. Process the data
  4. Forward the data to a database, file, web server, LLP, onto the queue, etc

To Push data to a web service

  1. Generate the data
  2. Push the data using net.http.put{}

Example

Try the Hello World web service, no authorization is needed.

In this case we get the data with net.http.get{}. Then we parse it with xml.parse{}, and finally we push the parsed data onto the queue for later processing.

To run the example:

  1. Create a From Translator –> To Channel channel
  2. Copy the code snippet into the From Translator script
URL = 'http://example.interfaceware.com:6544/hello'

function main()
   -- get data from web service
   local R = net.http.get{url=URL, live=true}

   -- parse and extract data
   local X = xml.parse{data=R}

   -- add data processing here

   -- push the result to the queue
   queue.push(X.text[1]:nodeValue())
end
Tagged:

Leave A Comment?

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.