DataFlex
DataFlex
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 DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoRest
Boolean iBTls
Boolean iBAutoReconnect
String sResponseText
String sTemp1
Boolean bTemp1
Move False To iSuccess
Get Create (RefClass(cComChilkatRest)) To hoRest
If (Not(IsComObjectCreated(hoRest))) Begin
Send CreateComObject of hoRest
End
// Connect to the REST server. The 3rd argument enables TLS (use True for HTTPS on port 443),
// and the 4th enables automatic reconnection if the connection is dropped between requests.
Move True To iBTls
Move True To iBAutoReconnect
Get ComConnect Of hoRest "example.com" 443 iBTls iBAutoReconnect To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoRest To sTemp1
Showln sTemp1
Procedure_Return
End
// 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.
Get ComAddPathParam Of hoRest "{userId}" "12345" To iSuccess
Get ComAddPathParam Of hoRest "{orderId}" "98765" To iSuccess
// The placeholders in the path are replaced before the request is sent.
Get ComFullRequestNoBody Of hoRest "GET" "/users/{userId}/orders/{orderId}" To sResponseText
Get ComLastMethodSuccess Of hoRest To bTemp1
If (bTemp1 = False) Begin
Get ComLastErrorText Of hoRest To sTemp1
Showln sTemp1
Procedure_Return
End
Showln sResponseText
End_Procedure