/
How to Create cURL Commands from Iguana HTTP API

How to Create cURL Commands from Iguana HTTP API

Summary

cURL and Iguana are compatible in the sense that they can be used together to achieve various integration tasks. Iguana provides a higher-level interface for designing and managing integrations, while cURL offers low-level control over network requests. Depending on your use case, you can leverage the strengths of each tool to create effective and efficient integration solutions.

This document will show you how to build cURL commands using an example from an HTTP Post request from Iguana’s HTTP API.

Considerations

cURL allows you to interact with web services and APIs directly from the command line, making it easy to integrate into scripts, automation, and various workflows. It is also highly adopted as cURL is available on a wide range of platforms, including Unix-like operating systems (Linux, macOS) and Windows, making it a portable solution for network interactions.

cURL commands can be easily integrated into scripts, batch files, and automation workflows, allowing you to automate repetitive tasks or build more complex interactions with web services.

How to

Here is the break down the building process of the cURL command based on the Iguana Status request API as an example:

local Status = net.http.post{ url='localhost:6543/status', auth={password='password',username='admin'}, parameters={action='start', name='ChannelName'}, live=true }

cURL Command:

curl -X POST \ -H "Content-Type: application/x-www-form-urlencoded" \ -d 'action=start&name=ChannelName' \ -u admin:password \ <http://localhost:6543/status> OR ON ONE LINE: curl -X POST -H "Content-Type: application/x-www-form-urlencoded" -d 'action=start&name=ChannelName' -u admin:password http://localhost:6543/status

Method

(-X POST): The cURL command begins with the -X option, specifying the HTTP method as POST. This corresponds to the Lua code's net.http.post method call.

Headers

(-H "Content-Type: application/x-www-form-urlencoded"): The -H option sets the Content-Type header to indicate that the request will contain form-urlencoded data. This matches the Lua code's use of application/x-www-form-urlencoded content type.

Data

(-d 'action=start&name=ChannelName'): The -d option specifies the data to be sent in the request body. This data is formatted as key=value pairs separated by ampersands (&). In the Lua code, the parameters table sets the action and name parameters with the values 'start' and ChannelName, respectively.

Basic Authentication

(-u admin:password): The -u option sets up basic authentication by providing the username (admin) and password (password). This mirrors the Lua code's use of authentication in the auth table.

URL

(<http://localhost:6543/status):> The URL of the endpoint is specified at the end of the cURL command. This corresponds to the url parameter in the Lua code.

 

By following the logic of the Lua code and understanding each component, you can construct the cURL command that achieves the same functionality as the original script.

Extra Command Settings

There are additional steps that can be added to the command such as:

  1. Timeout (--max-time ...): The --max-time option specifies the maximum time the request is allowed to take before timing out, matching the timeout setting in the Lua code.

  2. Follow Redirects (-L): The -L option instructs cURL to follow redirects, just like the follow_redirects setting in the Lua code.

  3. Response Output (-o -): The -o - option specifies that the response should be written to the console, simulating the behavior of response_sink in the Lua code.

Related content

Quick Rebuilding Corrupted Iguana Repo Solutions
Quick Rebuilding Corrupted Iguana Repo Solutions
Read with this
Creating or Testing HTTP Requests With an 'Echo' Channel
Creating or Testing HTTP Requests With an 'Echo' Channel
More like this
How to get a Channel Queued Messages
How to get a Channel Queued Messages
Read with this
Web Service
More like this
How to handle high volume of Iguana Instances
How to handle high volume of Iguana Instances
Read with this
How to Build Iguana License Automation
How to Build Iguana License Automation
More like this