This section contains answers to common questions about using Web Services with Iguana.
Note: You can set up SSL security certificates if you select a dedicated port.
Iguana’s built-in web server supports SSL, so you can connect to and create secure web services.
To connect to secure web service
You can use SSL with the net.http.xxx{}
library (get, put, post and delete), just put the SSL certificate details in the ssl
table parameter. For details see the API documentation net.http – using http connections.
The simplest connection code is something like this:
URL = 'https://<secure site name>' SSL = {cert='/filepath/to/self_cert_test_keys/c', key='/filepath/to/self_cert_test_keys/privkey.pem', verify_host=false, verify_peer=false} -- verify peer needs a "Certificate Authority file" function main() -- get data from secure web service local R = net.http.get{url=URL, live=true, ssl = SSL} trace(R) end
To create a secure web service
You must enable HTTPS in Setting>HTTP(S) Channel Settings and enter the SSL certificate file details (no code changes are required).
Note: If you select Verify Peer you will also need a Certificate Authority File.
To set the Iguana web server to use SSL
This will apply SSL to the Iguana web APIs, i.e., monitor_query{}
etc.
URL = 'https://localhost:6543/monitor_query' SSL = {cert='/filepath/to/self_cert_test_keys/c', key='/filepath/to/self_cert_test_keys/privkey.pem', verify_host=false, verify_peer=false} -- verify peer needs a "Certificate Authority file" AUTH = {username='admin',password='password'} function main() -- get data from secure web service local R = net.http.get{url=URL, live=true, auth=AUTH, ssl = SSL} trace(R) end
You must enable HTTPS in Setting>HTTP(S) Web Server Configuration and enter the SSL certificate file details (no code changes are required).
How to create self-certified SSL certificates for testing
A simple way to create your certificate and public key file is to use openssl. See how to create self-certified SSL certificate and public key files for more information.
Tip: You can also use SSL with the To/From LLP components and with net.ftps
, and net.smtp
.
You need to choose an event or events to trigger the Web Service call, you can use any event to trigger a web service call.
For example: Use a From Translator to poll a directory or a database, use From HTTPS to receive web service calls from a web page or application (useful to respond interactively to user input), use a From Translator and conditionally call a web service to add missing data or update incomplete data, or you could just schedule an hourly web service call.
Yes!
When using “From HTTP” components in channels it is possible to serve files from the web service port. This is useful when returning page data that contains embedded resources, such as images or javascript files, to a web browser.
Here is a simple “From HTTP” script that returns HTML data with an embedded image:
function main(Data) local TestHtml = [[ <html> <head><title>Test Html</title></head> <body> <img src="/interfaceware.gif"> </body> </html>]] net.http.respond{body=TestHtml} end
The root directory to serve files from can be configured in “HTTP(S) Channel Settings”:
In this case, the returned HTML data will request an image named “interfaceware.gif”, and Iguana will look for the file in the d:\temp directory.
Simple! Just use this is handy module for parsing URL encoded GET/POST sequences, i.e., LastName=Smith&FirstName=John&Dob=19722011 etc.
The code for the urlcode.lua
module can be downloaded from our code repository.
To enable socket reuse both the Iguana web client and the third party web server participating in an HTTP 1.1 conversation must be configured to reuse sockets with ‘Connection=Keep-Alive’.
For more information see: Evaluating Web Client Performance.