Using basic authentication
Contents
When connecting to authenticated web services, you use the HTTP API to pull or push the data, and the auth
parameter to supply the login information. The XML or JSON API can be very useful to parse or generate data.
Steps
To Pull data from a web service
- Pull data using
net.http.get{}
ornet.http.post{}
- Pass the login information using the
auth
parameter
- Pass the login information using the
- Parse the data
- Process the data
- Forward the data to a database, file, web server, LLP, onto the queue, etc
To Push data to a web service
- Generate the data
- Push the data using
net.http.put{}
- Pass the login information using the
auth
parameter
- Pass the login information using the
Example
Try the Get current date and time web service, username = admin and password = password.
In this case we get the data with net.http.get{}
using the auth
parameter to pass the login details. Then we parse it with xml.parse{}
, and finally we push the parsed data onto the queue for later processing.
To run the example:
- Create a From Translator –> To Channel channel
- Copy the code snippet into the From Translator script
require("node") URL = 'http://example.interfaceware.com:6544/current_time' USER = 'admin' PASSWORD = 'password' function main() -- get data from web service local R = net.http.get{url=URL, auth={username=USER, password=PASSWORD}, 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:S()) end
Back to: Without authentication