Without authentication
Contents
In general a web service takes in an HTTP request, processes it and sends a response.
Steps
- Take in an HTTP request using a From HTTPS channel component
- Parse the request into a Lua table using
net.http.parseRequest{}
- Process the parsed request
- Optional: Take some action based on the processing
- Send a response using
net.http.respond{}
Example
Try it now: Hello World, no authorization.
This web service is very simple! We just respond to an HTTP request by returning “Hello World” as XML. It’s implemented using a single channel set up with From HTTPS –> To Channel. We just take in an HTTP request, push the message to the queue, and return “Hello World” as XML.
To run the example
- Create a From HTTPS –> To Channel channel
- Set the Source > Use Translator to “Translator”
- Then set the “Source>URL path” to “hello”, and note the web link that is created
Note: The port number will be different from that used for Iguana: - Copy the code snippet into the From HTTPS script
- Use the URL from step 3 to access the web service
Note: The key value entity_type=’text/xml’ tells the receiver that the response is XML, rather than the default HTML (to prevent browsers from showing a blank screen).
function main(Data) -- parse the request data local R = net.http.parseRequest{data=Data} -- add data processing here -- push the result to the queue queue.push{data=Data} -- vary response based on processing net.http.respond{ entity_type='text/xml', body="<text>Hello World</text>", debug_result=true} end
Continue: Using basic authentication
Pingback: Auto-Generating Code for Easy Reporting and Alerts