Chilkat Examples

ChilkatHOMEAndroid™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi DLLGoJavaJavaScriptNode.jsObjective-CPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwiftTclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

DataFlex Examples
Web API Categories

AI
ASN.1
AWS KMS
AWS Misc
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Key Vault
Azure Service Bus
Azure Table Service
Base64
Box
CAdES
CSR
CSV
Cert Store
Certificates
Cloud Signature CSC
Code Signing
Compression
DKIM / DomainKey
DNS
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
EBICS
ECC
Ed25519
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
GMail SMTP/IMAP/POP
Geolocation
Google APIs
Google Calendar
Google Cloud SQL
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
Gzip
HTML-to-XML/Text
HTTP
HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
JavaScript
MHT / HTML Email
MIME
Markdown
Microsoft Graph
Misc
NTLM
OAuth1
OAuth2
OIDC
Office365
OneDrive
OpenSSL
Outlook
Outlook Calendar
Outlook Contact
PDF Signatures
PEM
PFX/P12
PKCS11
POP3
PRNG
REST
REST Misc
RSA
Regular Expressions
SCP
SCard
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
ScMinidriver
Secrets
SharePoint
Signing in the Cloud
Socket/SSL/TLS
Spider
Stream
Tar Archive
ULID/UUID
Upload
WebSocket
X
XAdES
XML
XML Digital Signatures
XMP
Zip
curl
uncategorized

 

 

 

(DataFlex) curl How Known Variables Reduce Execution Steps

See more CURL Examples

This example demonstrates how previously resolved values can simplify future executions.

When DoYourThing is called for a curl command, it builds an execution plan by resolving any missing inputs. This may require running one or more helper curl commands to produce the needed values.

As each command runs, any defined output variables are stored in the HttpCurl object and remain available for subsequent calls.

If another curl command is executed afterward—and it requires variables that are already known from earlier executions—those inputs do not need to be resolved again. As a result, the dependency chain is shorter, and the execution plan contains fewer steps.

In other words, each call to DoYourThing benefits from the current set of known variables. The more values that have already been resolved, the simpler and more direct the execution plan becomes.

This demonstrates that dependency resolution is dynamic and incremental: only missing inputs trigger additional steps, while previously computed values are reused automatically.

Note: This example requires Chilkat v11.5.0 or greater.

For more information, see https://www.chilkatsoft.com/curl_dependency_engine.asp

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoHttpCurl
    String sTargetCurl
    String sFnName
    String sJsonPath
    Variant vJsonOAuth2
    Handle hoJsonOAuth2
    Variant vPlanJson
    Handle hoPlanJson
    String sTargetCurl2
    String sTemp1

    Move False To iSuccess

    Move False To iSuccess

    // -----------------------------------------------------------------------------
    // NOTE:
    // This example builds on the earlier multi-step dependency example, where the
    // execution plan required multiple curl commands (getSite → getDrives → target).
    // 
    // If you have not seen that example, refer to it here: curl Multi-Step Dependency
    // 
    // 
    // In this example, we demonstrate how previously resolved variables (site_id,
    // drive_id, etc.) are reused across multiple calls to DoYourThing, resulting
    // in simpler execution plans for subsequent requests.
    // -----------------------------------------------------------------------------

    Get Create (RefClass(cComChilkatHttpCurl)) To hoHttpCurl
    If (Not(IsComObjectCreated(hoHttpCurl))) Begin
        Send CreateComObject of hoHttpCurl
    End

    // The final curl command we want to execute.
    // It depends on {{drive_id}}, which may or may not already be known.
    Move "curl -X GET https://graph.microsoft.com/v1.0/drives/{{drive_id}}/root/children" To sTargetCurl

    // Define helper function to get drives (produces drive_id, requires site_id)
    Move "getDrives" To sFnName
    Get ComAddFunction Of hoHttpCurl sFnName "curl -X GET https://graph.microsoft.com/v1.0/sites/{{site_id}}/drives" To iSuccess
    Move "value[0].id" To sJsonPath
    Get ComAddOutput Of hoHttpCurl sFnName sJsonPath "drive_id" To iSuccess

    // Define helper function to get site (produces site_id, requires site_name)
    Move "getSite" To sFnName
    Get ComAddFunction Of hoHttpCurl sFnName "GET https://graph.microsoft.com/v1.0/sites/root:/sites/{{site_name}}" To iSuccess
    Move "id" To sJsonPath
    Get ComAddOutput Of hoHttpCurl sFnName sJsonPath "site_id" To iSuccess

    // Provide the initial known input.
    Send ComSetVar To hoHttpCurl "site_name" "test"

    // Configure OAuth2 authentication (client credentials with secrets)
    Get Create (RefClass(cComChilkatJsonObject)) To hoJsonOAuth2
    If (Not(IsComObjectCreated(hoJsonOAuth2))) Begin
        Send CreateComObject of hoJsonOAuth2
    End
    Set ComEnableSecrets Of hoJsonOAuth2 To True
    Get ComUpdateString Of hoJsonOAuth2 "oauth2.client_id" "!!sharepoint|oauth2|client_id" To iSuccess
    Get ComUpdateString Of hoJsonOAuth2 "oauth2.client_secret" "!!sharepoint|oauth2|client_secret" To iSuccess
    Get ComUpdateString Of hoJsonOAuth2 "oauth2.scope" "https://graph.microsoft.com/.default" To iSuccess
    Get ComUpdateString Of hoJsonOAuth2 "oauth2.token_endpoint" "!!sharepoint|oauth2|token_endpoint" To iSuccess
    Get pvComObject of hoJsonOAuth2 to vJsonOAuth2
    Get ComSetAuth Of hoHttpCurl vJsonOAuth2 To iSuccess

    // -----------------------------------------------------------------------------
    // EXAMINE THE EXECUTION PLAN (BEFORE RUNNING):
    // At this point, drive_id and site_id are NOT known.
    // We can inspect the plan that will be executed without sending any requests.
    // -----------------------------------------------------------------------------
    Get Create (RefClass(cComChilkatJsonObject)) To hoPlanJson
    If (Not(IsComObjectCreated(hoPlanJson))) Begin
        Send CreateComObject of hoPlanJson
    End
    Set ComEmitCompact Of hoPlanJson To False

    Get pvComObject of hoPlanJson to vPlanJson
    Get ComExaminePlan Of hoHttpCurl sTargetCurl vPlanJson To iSuccess
    Showln "Execution plan before first call:"
    Get ComEmit Of hoPlanJson To sTemp1
    Showln sTemp1

    // Expected output:
    // 
    // {
    //   "plan": [{
    //     "function": "getSite",
    //     "inputs": ["site_name"],
    //     "outputs": ["site_id"]
    //   },{
    //     "function": "getDrives",
    //     "inputs": ["site_id"],
    //     "outputs": ["drive_id"]
    //   },{
    //     "function": "targetCurl",
    //     "inputs": ["drive_id"],
    //     "outputs": []
    //   }]
    // }

    // -----------------------------------------------------------------------------
    // FIRST CALL:
    // At this point, drive_id and site_id are NOT known.
    // The execution plan will include all required steps:
    // 
    //   1) getSite    → produces site_id
    //   2) getDrives  → produces drive_id
    //   3) targetCurl → uses drive_id
    // -----------------------------------------------------------------------------
    Get ComDoYourThing Of hoHttpCurl sTargetCurl To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoHttpCurl To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Showln "First call completed."
    Get ComGetVar Of hoHttpCurl "site_id" To sTemp1
    Showln "site_id  = " sTemp1
    Get ComGetVar Of hoHttpCurl "drive_id" To sTemp1
    Showln "drive_id = " sTemp1

    // -----------------------------------------------------------------------------
    // SECOND CALL (DIFFERENT TARGET):
    // Now that site_id is already known, we can run another curl command that
    // depends only on site_id. No need to call getSite again.
    // 
    // Execution plan:
    // 
    //   1) targetCurl2 → uses existing site_id
    // -----------------------------------------------------------------------------

    Move "curl -X GET https://graph.microsoft.com/v1.0/sites/{{site_id}}" To sTargetCurl2

    Get pvComObject of hoPlanJson to vPlanJson
    Get ComExaminePlan Of hoHttpCurl sTargetCurl2 vPlanJson To iSuccess
    Showln ""
    Get ComEmit Of hoPlanJson To sTemp1
    Showln sTemp1

    // Expected output:
    // 
    // {
    //   "plan": [{
    //     "function": "targetCurl",
    //     "inputs": ["site_id"],
    //     "outputs": []
    //   }]
    // }

    Get ComDoYourThing Of hoHttpCurl sTargetCurl To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoHttpCurl To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Showln "Second call completed (used existing site_id)."

    // -----------------------------------------------------------------------------
    // THIRD CALL (ORIGINAL TARGET AGAIN):
    // drive_id is already known from the first call.
    // Therefore, no helper functions are needed this time.
    // 
    // Execution plan:
    // 
    //   1) targetCurl → uses existing drive_id
    // -----------------------------------------------------------------------------
    Get pvComObject of hoPlanJson to vPlanJson
    Get ComExaminePlan Of hoHttpCurl sTargetCurl vPlanJson To iSuccess
    Showln ""
    Get ComEmit Of hoPlanJson To sTemp1
    Showln sTemp1

    // Expected output:
    // 
    // {
    //   "plan": [{
    //     "function": "targetCurl",
    //     "inputs": ["drive_id"],
    //     "outputs": []
    //   }]
    // }

    Get ComDoYourThing Of hoHttpCurl sTargetCurl To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoHttpCurl To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Showln "Third call completed."
    Showln "No dependency resolution was needed because all inputs were already known."


End_Procedure

 

© 2000-2026 Chilkat Software, Inc. All Rights Reserved.