DataFlex
DataFlex
Use an Existing Socket Connection for REST
See more REST Examples
Demonstrates Rest.UseConnection, which supplies an already-connected Socket as the transport for REST requests instead of calling Connect. This is useful when the connection must be established with specific socket options or shared across objects.
Background. Rest can operate over any connected socket. The second argument enables automatic reconnection so a dropped connection is transparently re-established between requests.
Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Variant vSocket
Handle hoSocket
Boolean iBSsl
Handle hoRest
Boolean iBAutoReconnect
String sResponseText
String sTemp1
Boolean bTemp1
Move False To iSuccess
// Demonstrates supplying an already-connected socket for the REST transport. This is useful when
// the connection must be established with specific socket options, or reused across objects.
Get Create (RefClass(cComChilkatSocket)) To hoSocket
If (Not(IsComObjectCreated(hoSocket))) Begin
Send CreateComObject of hoSocket
End
Move True To iBSsl
Get ComConnect Of hoSocket "example.com" 443 iBSsl 5000 To iSuccess
If (iSuccess <> True) Begin
Get ComLastErrorText Of hoSocket To sTemp1
Showln sTemp1
Procedure_Return
End
Get Create (RefClass(cComChilkatRest)) To hoRest
If (Not(IsComObjectCreated(hoRest))) Begin
Send CreateComObject of hoRest
End
// Use the connected socket as the transport. The 2nd argument enables automatic reconnection.
Move True To iBAutoReconnect
Get pvComObject of hoSocket to vSocket
Get ComUseConnection Of hoRest vSocket iBAutoReconnect To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoRest To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComFullRequestNoBody Of hoRest "GET" "/api/status" 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