webservice developed with mod_harbour

mod_harbour is an Apache module that allows to run PRGs directly on the web !!!

webservice developed with mod_harbour

Postby Antonio Linares » Fri Feb 21, 2020 10:44 am

webservice.prg
Code: Select all  Expand view
function Main()

   AP_SetContentType( "application/json" )

   ?? hb_jsonEncode( { "Method" => AP_Method(), "Args" => AP_Args(), "Body" => AP_Body() } )

return nil


live demo:
https://fivetechsoft.github.io/snippets?20200224184548

Accessing the webservice from mod_harbour:
Code: Select all  Expand view
#include "/home/user/harbour/contrib/hbcurl/hbcurl.ch"

function Main()

   ? UseWebService()
   
return nil  

function UseWebService()

   local uValue

   curl_global_init()

   if ! empty( hCurl := curl_easy_init() )
        curl_easy_setopt( hCurl, HB_CURLOPT_POST, 1 )
        curl_easy_setopt( hCurl, HB_CURLOPT_URL, "http://www.modharbour.org/modharbour_samples/webservice.prg" )
        curl_easy_setopt( hCurl, HB_CURLOPT_DL_BUFF_SETUP )
        curl_easy_setopt( hCurl, HB_CURLOPT_POSTFIELDS, hb_jsonEncode( { "key1" => "value1", "key2" => "value2", "key3" => "value3" } ) )

        if curl_easy_perform( hCurl ) == 0
           uValue = curl_easy_dl_buff_get( hCurl )
        endif
   endif

   curl_global_cleanup()

return uValue
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42078
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Return to mod_harbour

Who is online

Users browsing this forum: No registered users and 8 guests