HttpCurl Class Overview

The HttpCurl class is a curl-compatible HTTP execution engine with built-in dependency resolution. It allows applications to execute curl commands directly, while automatically obtaining prerequisite values required by the request.

At its simplest, HttpCurl can execute a single curl command and provide access to the HTTP response. However, its primary purpose is to automate multi-step workflows where one HTTP request depends on values obtained from earlier requests.

For example, an application may need to:

  1. Authenticate and obtain an access token.
  2. Query an API to locate a resource ID.
  3. Use the resource ID in a final request.

Rather than manually performing each step, the HttpCurl class can determine the required sequence of requests and execute them automatically.

New in v11.7.0 — variables can be used in two more places:

Dependency Resolution

Variables are represented using double braces:

{{access_token}}
{{site_id}}
{{drive_id}}

Variables can appear anywhere within a curl command, including:

  • URL paths
  • Query parameters
  • Request headers
  • Request bodies
  • The local output file path v11.7.0 — see Output File Paths

They may also appear in an output mapping, which is not part of the curl command itself v11.7.0 — see Variables in Output Mappings.

When a curl command contains undefined variables, HttpCurl constructs an execution plan based on previously defined curl functions and output mappings. It then executes the necessary requests to obtain the missing values before executing the target request.

For example:

curl https://graph.microsoft.com/v1.0/drives/{{drive_id}}/items

If drive_id is not yet known, HttpCurl can automatically execute one or more dependency functions to determine its value.

Defining Functions

Dependency functions are added using AddFunction.

Each function contains a curl command that can produce one or more output variables. Outputs are defined using AddOutput or AddOutput2, which specify how values are extracted from JSON responses.

For example:

httpCurl.AddFunction(
    "GetDrive",
    "curl https://api.example.com/drives");

httpCurl.AddOutput(
    "GetDrive",
    "id",
    "drive_id");

When drive_id is required by another request, HttpCurl knows that it can execute GetDrive to obtain the value.

Variables in Output Mappings v11.7.0

AddOutput2 takes a value from one element of a JSON array, identifying that element by a path and a value to match. Starting in v11.7.0, the arrayPath, wherePath, whereValue and subPath arguments may each contain variable names enclosed in {{ and }}. The record an output is taken from therefore no longer has to be identified by a value the application knows in advance.

For example, to take the id of the drive whose name is the current value of drive_name:

httpCurl.SetVar("drive_name","Shared Documents");

httpCurl.AddFunction(
    "listDrives",
    "curl https://graph.example.com/sites/{{site_id}}/drives");

httpCurl.AddOutput2(
    "listDrives",
    "drives",
    "name",
    "{{drive_name}}",
    true,
    "id",
    "drive_id");

Each of the four arguments is stored exactly as passed, and the references in it are resolved every time that output is evaluated — not when AddOutput2 was called. The variable's current value is the one used, whether it was assigned with SetVar or produced as the output of another curl function. A reference may be the whole value or part of a longer string, such as result.{{list_name}}.items.

A variable referenced in an output mapping is treated as an input of the curl function, exactly like one appearing in the curl command itself. The execution plan therefore runs whatever produces that variable before running the function that needs it.

The caseSensitive argument is not text and is never substituted. The jsonPath of the simpler AddOutput does not take variable references.

Target Outputs

The final target request can also produce variables.

Target outputs are defined using AddTargetOutput, allowing values returned by one request to be automatically stored and reused by future requests.

This makes it possible to build long-running workflows where information discovered by one request becomes available to subsequent requests.

Variable Management

Variables may be:

  • Explicitly assigned using SetVar
  • Automatically extracted from dependency functions
  • Automatically extracted from target responses

Variables remain defined until cleared using ClearVar.

This allows previously discovered values to be reused without repeating unnecessary HTTP requests.

Execution Planning

The DoYourThing method executes a target curl command.

Before execution, HttpCurl examines the command and determines which variables are already known and which must be resolved. It then builds an execution plan that satisfies all dependencies and executes each step in the required order.

The ExaminePlan method can be used to inspect the generated plan without executing it, making it useful for debugging and development.

Authorization

Authorization settings can be configured globally using SetAuth.

The authorization configuration is automatically applied to all HTTP requests executed by the HttpCurl instance, including dependency-resolution requests and target requests.

Response Handling

After execution, the response is available through:

  • ResponseBodyStr
  • GetResponseBd
  • GetResponseSb
  • GetResponseJson
  • GetResponseXml
  • GetResponseJarr

Large responses can be streamed directly to a file by setting ResponseFilePath.

Output File Paths

A curl command may name the file the response body is written to, using the same options as curl:

  • -o / --output — an explicit filename.
  • -O / --remote-name — the filename is the final path segment of the URL.
  • --output-dir — the directory to write into. As in curl, it is applied only when the filename itself contains no directory separator.

This is independent of the ResponseFilePath property, which streams the response body to a file for requests whose curl command names no output file.

Variables in the output file path v11.7.0

Starting in v11.7.0, the output file path may contain variable names enclosed in {{ and }}, resolved from the current variable values at the time the request is sent. This applies to the path given with -o, the directory given with --output-dir, and the URL that -O derives a filename from.

In previous versions the path was used exactly as written, so -o "{{report_name}}.pdf" created a file whose name was literally {{report_name}}.pdf. Braces are legal in filenames on both Windows and Linux, so this succeeded and reported success.

httpCurl.SetVar("customer","acme");
httpCurl.SetVar("report_name","q3-summary");

httpCurl.DoYourThing(
    "curl https://api.example.com/reports/{{report_name}} "
    "--output-dir \"reports/{{customer}}\" -o \"{{report_name}}.pdf\"");

// writes reports/acme/q3-summary.pdf

Two conditions cause the request to fail rather than write a file:

  • The resolved path still contains a {{varName}} reference, or a variable in it resolved to an empty string. Elsewhere — in a URL or a request body — an unresolved reference is left in place, but in a file path that would silently create a misnamed file.
  • A variable substituted into the path has a value containing a .. directory segment. Because a variable's value can come from a server's response, a response must not be able to move the output file out of the directory the curl command named. A .. written literally in the curl command itself is the application's own choice and is allowed.

The path as it will actually be used is written to LastErrorText as resolvedOutputPath.

Debugging Support

Several features are available to assist with troubleshooting:

  • ExaminePlan shows the dependency-resolution plan.
  • ToRawRequest converts a curl command into the raw HTTP request that would be sent.
  • FailedCurl identifies the curl command that failed.
  • FailReason provides a categorized failure code.
  • LastErrorText contains detailed diagnostic information.

Typical Use Cases

The HttpCurl class is particularly useful for:

  • REST API automation
  • OAuth and token-based authentication workflows
  • Microsoft Graph and SharePoint operations
  • Cloud service APIs with multiple dependency steps
  • Resource discovery and lookup workflows
  • Complex HTTP integrations where later requests depend on data returned by earlier requests

By combining curl compatibility with automatic dependency resolution, HttpCurl enables complex HTTP workflows to be expressed as a set of interconnected curl commands while allowing the library to determine and execute the required sequence of requests.