PowerBuilder
PowerBuilder
Add a Path Substitution Parameter to a REST Request
See more REST Examples
Demonstrates Rest.AddPathParam, which adds or replaces a path-substitution parameter. Before a request is sent, each occurrence of the name in the URI path is replaced with its value.
Background. Path parameters keep a URI path template readable—placeholders such as
{userId} are substituted with concrete values just before the request is sent.Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Rest
integer li_BTls
integer li_BAutoReconnect
string ls_ResponseText
li_Success = 0
loo_Rest = create oleobject
li_rc = loo_Rest.ConnectToNewObject("Chilkat.Rest")
if li_rc < 0 then
destroy loo_Rest
MessageBox("Error","Connecting to COM object failed")
return
end if
// Connect to the REST server. The 3rd argument enables TLS (use 1 for HTTPS on port 443),
// and the 4th enables automatic reconnection if the connection is dropped between requests.
li_BTls = 1
li_BAutoReconnect = 1
li_Success = loo_Rest.Connect("example.com",443,li_BTls,li_BAutoReconnect)
if li_Success = 0 then
Write-Debug loo_Rest.LastErrorText
destroy loo_Rest
return
end if
// Add path-substitution parameters. Before a request is sent, each occurrence of the name in the
// URI path is replaced with the value. This keeps the path template readable.
loo_Rest.AddPathParam("{userId}","12345")
loo_Rest.AddPathParam("{orderId}","98765")
// The placeholders in the path are replaced before the request is sent.
ls_ResponseText = loo_Rest.FullRequestNoBody("GET","/users/{userId}/orders/{orderId}")
if loo_Rest.LastMethodSuccess = 0 then
Write-Debug loo_Rest.LastErrorText
destroy loo_Rest
return
end if
Write-Debug ls_ResponseText
destroy loo_Rest