Call a webservice

Introduction

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.

In this example we get the weather in London from the OpenWeatherMap web service.

If you have any questions please contact us at support@interfaceware.com.

Using the Code [top]

  • Import the Call a webservice channel from the Builtin: Iguana Webservices repository
  • Setup the OpenWeatherMap API
    Note: If the key used in the code is still working you can omit this step

    • Sign up here to get your own api key
    • Paste your key into the code:
  • Experiment with the code to find out how it works
    • Start the channel
    • View the result using the URL specified in the channel source component:
  • Adapt the code to your own requirements
  • Interactive scripting help is included for this module

This is the github code for the main module:

How it works [top]

This is a simple example of calling a web service and serving up the data. In this case we get the weather in London from the OpenWeatherMap web service.

The process is very straightforward:

  1. Use net.http.get to call the web service
  2. Parse the returned data with json.parse
  3. Serve the result into a web page using net.http.respond

Note: Data is usually returned as XML or JSON and can be parsed using xml.parse or json.parse.

More information [top]

Leave A Comment?