![]() |
Chilkat HOME Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi DLL Go Java JavaScript Node.js Objective-C PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(PowerBuilder) curl How Known Variables Reduce Execution StepsSee more CURL ExamplesThis example demonstrates how previously resolved values can simplify future executions. When As each command runs, any defined output variables are stored in the If another In other words, each call to 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
integer li_rc integer li_Success oleobject loo_HttpCurl string ls_TargetCurl string ls_FnName string ls_JsonPath oleobject loo_JsonOAuth2 oleobject loo_PlanJson string ls_TargetCurl2 li_Success = 0 li_Success = 0 // ----------------------------------------------------------------------------- // 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. // ----------------------------------------------------------------------------- loo_HttpCurl = create oleobject li_rc = loo_HttpCurl.ConnectToNewObject("Chilkat.HttpCurl") if li_rc < 0 then destroy loo_HttpCurl MessageBox("Error","Connecting to COM object failed") return end if // The final curl command we want to execute. // It depends on {{drive_id}}, which may or may not already be known. ls_TargetCurl = "curl -X GET https://graph.microsoft.com/v1.0/drives/{{drive_id}}/root/children" // Define helper function to get drives (produces drive_id, requires site_id) ls_FnName = "getDrives" loo_HttpCurl.AddFunction(ls_FnName,"curl -X GET https://graph.microsoft.com/v1.0/sites/{{site_id}}/drives") ls_JsonPath = "value[0].id" loo_HttpCurl.AddOutput(ls_FnName,ls_JsonPath,"drive_id") // Define helper function to get site (produces site_id, requires site_name) ls_FnName = "getSite" loo_HttpCurl.AddFunction(ls_FnName,"GET https://graph.microsoft.com/v1.0/sites/root:/sites/{{site_name}}") ls_JsonPath = "id" loo_HttpCurl.AddOutput(ls_FnName,ls_JsonPath,"site_id") // Provide the initial known input. loo_HttpCurl.SetVar("site_name","test") // Configure OAuth2 authentication (client credentials with secrets) loo_JsonOAuth2 = create oleobject li_rc = loo_JsonOAuth2.ConnectToNewObject("Chilkat.JsonObject") loo_JsonOAuth2.EnableSecrets = 1 loo_JsonOAuth2.UpdateString("oauth2.client_id","!!sharepoint|oauth2|client_id") loo_JsonOAuth2.UpdateString("oauth2.client_secret","!!sharepoint|oauth2|client_secret") loo_JsonOAuth2.UpdateString("oauth2.scope","https://graph.microsoft.com/.default") loo_JsonOAuth2.UpdateString("oauth2.token_endpoint","!!sharepoint|oauth2|token_endpoint") loo_HttpCurl.SetAuth(loo_JsonOAuth2) // ----------------------------------------------------------------------------- // 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. // ----------------------------------------------------------------------------- loo_PlanJson = create oleobject li_rc = loo_PlanJson.ConnectToNewObject("Chilkat.JsonObject") loo_PlanJson.EmitCompact = 0 li_Success = loo_HttpCurl.ExaminePlan(ls_TargetCurl,loo_PlanJson) Write-Debug "Execution plan before first call:" Write-Debug loo_PlanJson.Emit() // 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 // ----------------------------------------------------------------------------- li_Success = loo_HttpCurl.DoYourThing(ls_TargetCurl) if li_Success = 0 then Write-Debug loo_HttpCurl.LastErrorText destroy loo_HttpCurl destroy loo_JsonOAuth2 destroy loo_PlanJson return end if Write-Debug "First call completed." Write-Debug "site_id = " + loo_HttpCurl.GetVar("site_id") Write-Debug "drive_id = " + loo_HttpCurl.GetVar("drive_id") // ----------------------------------------------------------------------------- // 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 // ----------------------------------------------------------------------------- ls_TargetCurl2 = "curl -X GET https://graph.microsoft.com/v1.0/sites/{{site_id}}" li_Success = loo_HttpCurl.ExaminePlan(ls_TargetCurl2,loo_PlanJson) Write-Debug "" Write-Debug loo_PlanJson.Emit() // Expected output: // // { // "plan": [{ // "function": "targetCurl", // "inputs": ["site_id"], // "outputs": [] // }] // } li_Success = loo_HttpCurl.DoYourThing(ls_TargetCurl) if li_Success = 0 then Write-Debug loo_HttpCurl.LastErrorText destroy loo_HttpCurl destroy loo_JsonOAuth2 destroy loo_PlanJson return end if Write-Debug "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 // ----------------------------------------------------------------------------- li_Success = loo_HttpCurl.ExaminePlan(ls_TargetCurl,loo_PlanJson) Write-Debug "" Write-Debug loo_PlanJson.Emit() // Expected output: // // { // "plan": [{ // "function": "targetCurl", // "inputs": ["drive_id"], // "outputs": [] // }] // } li_Success = loo_HttpCurl.DoYourThing(ls_TargetCurl) if li_Success = 0 then Write-Debug loo_HttpCurl.LastErrorText destroy loo_HttpCurl destroy loo_JsonOAuth2 destroy loo_PlanJson return end if Write-Debug "Third call completed." Write-Debug "No dependency resolution was needed because all inputs were already known." destroy loo_HttpCurl destroy loo_JsonOAuth2 destroy loo_PlanJson |
||||
© 2000-2026 Chilkat Software, Inc. All Rights Reserved.