Sample code for 30+ languages & platforms
PowerBuilder Requires Chilkat v11.5.0+

curl with Path Variables and Query Param Variables

See more CURL Examples

This example demonstrates using variables located in the path and query params with the {{variable_name}} syntax.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
string ls_TargetCurl
oleobject loo_HttpCurl
oleobject loo_ResponseJson
integer li_StatusCode

li_Success = 0

//  Variables can occur in the path and query params.  
//  Variable names are enclosed between {{ and }}

//   curl -X GET https://httpbin.org/{{verb}}?id={id_value}}
ls_TargetCurl = "curl -X GET https://httpbin.org/{{verb}}?id={{id_value}}"

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

//  Provide values for variables.
//  In this example, "verb" is a path variable, and "id_value" is a query param variable.
loo_HttpCurl.SetVar("verb","get")
loo_HttpCurl.SetVar("id_value","123")

//  Run the curl command.
li_Success = loo_HttpCurl.DoYourThing(ls_TargetCurl)
if li_Success = 0 then
    Write-Debug loo_HttpCurl.LastErrorText
    destroy loo_HttpCurl
    return
end if

loo_ResponseJson = create oleobject
li_rc = loo_ResponseJson.ConnectToNewObject("Chilkat.JsonObject")

loo_ResponseJson.EmitCompact = 0

li_StatusCode = loo_HttpCurl.StatusCode
Write-Debug "response status code: " + string(li_StatusCode)

loo_HttpCurl.GetResponseJson(loo_ResponseJson)
Write-Debug loo_ResponseJson.Emit()

//  Output:

//  response status code: 200
//  {
//    "args": {
//      "id": "123"
//    },
//    "headers": {
//      "Host": "httpbin.org",
//      "X-Amzn-Trace-Id": "Root=1-69e92914-5d4136d240f2f7fe1056f126"
//    },
//    "origin": "222.222.222.222",
//    "url": "https://httpbin.org/get?id=123"
//  }


destroy loo_HttpCurl
destroy loo_ResponseJson