Sample code for 30+ languages & platforms
PowerBuilder

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 PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Socket
integer li_BSsl
oleobject loo_Rest
integer li_BAutoReconnect
string ls_ResponseText

li_Success = 0

//  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.

loo_Socket = create oleobject
li_rc = loo_Socket.ConnectToNewObject("Chilkat.Socket")
if li_rc < 0 then
    destroy loo_Socket
    MessageBox("Error","Connecting to COM object failed")
    return
end if
li_BSsl = 1
li_Success = loo_Socket.Connect("example.com",443,li_BSsl,5000)
if li_Success <> 1 then
    Write-Debug loo_Socket.LastErrorText
    destroy loo_Socket
    return
end if

loo_Rest = create oleobject
li_rc = loo_Rest.ConnectToNewObject("Chilkat.Rest")

//  Use the connected socket as the transport.  The 2nd argument enables automatic reconnection.
li_BAutoReconnect = 1
li_Success = loo_Rest.UseConnection(loo_Socket,li_BAutoReconnect)
if li_Success = 0 then
    Write-Debug loo_Rest.LastErrorText
    destroy loo_Socket
    destroy loo_Rest
    return
end if

ls_ResponseText = loo_Rest.FullRequestNoBody("GET","/api/status")
if loo_Rest.LastMethodSuccess = 0 then
    Write-Debug loo_Rest.LastErrorText
    destroy loo_Socket
    destroy loo_Rest
    return
end if

Write-Debug ls_ResponseText


destroy loo_Socket
destroy loo_Rest