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) Invalidating Dependent Variables When Inputs Change

See more CURL Examples

This example demonstrates how HttpCurl automatically updates the execution plan when a known variable is cleared or changed.

After a multi-step execution plan runs successfully, variables such as site_id and drive_id may become known. Later calls to DoYourThing can reuse those values, resulting in a shorter execution plan.

However, if an input variable is cleared using ClearVar, or changed using SetVar, any variables that depend on that value are automatically invalidated. This ensures that stale values are not reused.

For example, if site_name changes, then the previously resolved site_id is no longer valid. Because drive_id depends on site_id, it is also invalidated. The next execution plan is rebuilt to resolve the dependency chain again using the new input value.

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
    Variant vJsonOAuth2
    Handle hoJsonOAuth2
    Variant vPlanJson
    Handle hoPlanJson
    String sTemp1
    Boolean bTemp1

    Move False To iSuccess

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

    // The target curl command we ultimately want to execute.
    // It requires drive_id.
    Move "curl -X GET https://graph.microsoft.com/v1.0/drives/{{drive_id}}/root/children" To sTargetCurl

    // Define a helper function that produces drive_id.
    // This 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
    Get ComAddOutput Of hoHttpCurl sFnName "value[0].id" "drive_id" To iSuccess

    // Define another helper function that produces site_id.
    // This requires site_name.
    Move "getSite" To sFnName
    Get ComAddFunction Of hoHttpCurl sFnName "curl -X GET https://graph.microsoft.com/v1.0/sites/root:/sites/{{site_name}}" To iSuccess
    Get ComAddOutput Of hoHttpCurl sFnName "id" "site_id" To iSuccess

    // site_name is the starting known value.
    Send ComSetVar To hoHttpCurl "site_name" "test"

    // Configure OAuth2 authentication.
    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

    // -----------------------------------------------------------------------------
    // First execution plan:
    // site_id and drive_id are not known yet, so the full dependency chain is needed.
    // -----------------------------------------------------------------------------
    Get Create (RefClass(cComChilkatJsonObject)) To hoPlanJson
    If (Not(IsComObjectCreated(hoPlanJson))) Begin
        Send CreateComObject of hoPlanJson
    End
    Set ComEmitCompact Of hoPlanJson To False

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

    // Expected:
    // 
    // {
    //   "plan": [{
    //     "function": "getSite",
    //     "inputs": ["site_name"],
    //     "outputs": ["site_id"]
    //   },{
    //     "function": "getDrives",
    //     "inputs": ["site_id"],
    //     "outputs": ["drive_id"]
    //   },{
    //     "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 "After first call:"
    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 execution plan:
    // site_id and drive_id are now known, so only the target curl command is needed.
    // -----------------------------------------------------------------------------
    Showln "Execution plan after first call:"
    Get pvComObject of hoPlanJson to vPlanJson
    Get ComExaminePlan Of hoHttpCurl sTargetCurl vPlanJson To iSuccess
    Get ComEmit Of hoPlanJson To sTemp1
    Showln sTemp1

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

    // -----------------------------------------------------------------------------
    // Change the original input.
    // Because site_id was produced from site_name, changing site_name invalidates site_id.
    // Because drive_id depends on site_id, drive_id is also invalidated.
    // -----------------------------------------------------------------------------

    // Note: Make sure this site exists on in your SharePoint...
    Send ComSetVar To hoHttpCurl "site_name" "anotherSite"

    Showln "After changing site_name:"
    Get ComVarDefined Of hoHttpCurl "site_id" To bTemp1
    Showln "site_id defined?  " bTemp1
    Get ComVarDefined Of hoHttpCurl "drive_id" To bTemp1
    Showln "drive_id defined? " bTemp1

    // -----------------------------------------------------------------------------
    // The execution plan is automatically rebuilt.
    // Since site_id and drive_id were invalidated, the full dependency chain is needed again.
    // -----------------------------------------------------------------------------
    Showln "Execution plan after changing site_name:"
    Get pvComObject of hoPlanJson to vPlanJson
    Get ComExaminePlan Of hoHttpCurl sTargetCurl vPlanJson To iSuccess
    Get ComEmit Of hoPlanJson To sTemp1
    Showln sTemp1

    // Expected:
    // 
    // {
    //   "plan": [{
    //     "function": "getSite",
    //     "inputs": ["site_name"],
    //     "outputs": ["site_id"]
    //   },{
    //     "function": "getDrives",
    //     "inputs": ["site_id"],
    //     "outputs": ["drive_id"]
    //   },{
    //     "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 "After running again with the new site_name:"
    Get ComGetVar Of hoHttpCurl "site_id" To sTemp1
    Showln "site_id  = " sTemp1
    Get ComGetVar Of hoHttpCurl "drive_id" To sTemp1
    Showln "drive_id = " sTemp1

    // -----------------------------------------------------------------------------
    // Clearing a variable also invalidates values that depend on it.
    // Here, clearing site_id also invalidates drive_id.
    // -----------------------------------------------------------------------------
    Send ComClearVar To hoHttpCurl "site_id"

    Showln "After clearing site_id:"
    Get ComVarDefined Of hoHttpCurl "site_id" To bTemp1
    Showln "site_id defined?  " bTemp1
    Get ComVarDefined Of hoHttpCurl "drive_id" To bTemp1
    Showln "drive_id defined? " bTemp1

    Showln "Execution plan after clearing site_id:"
    Get pvComObject of hoPlanJson to vPlanJson
    Get ComExaminePlan Of hoHttpCurl sTargetCurl vPlanJson To iSuccess
    Get ComEmit Of hoPlanJson To sTemp1
    Showln sTemp1

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


End_Procedure

 

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