So I had an interesting problem the other day with helping a client get a more transparent solution for doing an HTTP post to a web service they had.
One of the great things about the translator in Iguana is how open the platform is. This shows the implementation of an HTTP client in pure Lua. It makes use of the net.tcp.* calls to create a raw socket and then all the HTTP protocol pieces are implemented on that API.
What are the advantages? Well it’s more transparent – it makes it easier to see explicitly what is being sent and what is coming back from the web server we are sending to. It’s simpler to implement persistent HTTP connections and see the lifetime of the socket in question.
When you use net.http.post it’s a blocking synchronous call, whereas with this HTTP client written in Lua you could post off several requests in a row before waiting for the results to come back. So it offers the ability to different kinds of optimizations in terms of throughput.
Anyway I figured it might be useful so have attached the zip file for the To Translator instance which has the code in it. It’s always handy to have a few different tools available to solve a specific problem.
This particular example comes with an example of using some logic to retry if the HTTP connection fails. If you have an interest in this or any questions let me know.