Uniface User Forum

 View Only
  • 1.  Call-in for Uniface Service using REST API instead WebService

    Posted 09-03-2024 13:30

    Dear all,

    I´m looking for some documentation about how to publish a Uniface Service operation (call-in) thru REST API instead regular WebServices.  

    Any ideal will be welcome.

    Best regards,

    Marcelo Martins



    ------------------------------
    Marcelo Martins
    Uniface Consultant
    Vertti Tecnologia Da Informa
    Maringa PR BR
    ------------------------------


  • 2.  RE: Call-in for Uniface Service using REST API instead WebService

    Posted 09-04-2024 07:17

    REST services are 'just' webpages. 

    So you need to write a USP which can process the input/url called to parse them and perform the required actions/return the required data. 

    Here are the top and bottom of our basic API usp 

    operation exec
    PUBLIC WEB
    variables 
    	string  v_url ,v_params, v_id, v_data
    	struct v_output
    endvariables
    
    v_params = $webinfo("input")
    v_url = $webinfo("pathinput")
    

    structtojson v_data, v_output
    putitem/id $webinfo("HTTPRESPONSEHEADERS"),"Content-Type","application/json; charset=utf-8"
    
    $webinfo("output") = v_data
    
    return(0)

    The code in the middle parses v_url for the entity/function required and v_params for the data. 
    The response is then built in a struct (v_struct) and transposed to JSON for output by the end of the proc. 

    Hope this helps, 

    Iain



    ------------------------------
    Iain Sharp
    Head of Technical Services
    Pci Systems Ltd
    Sheffield GB
    ------------------------------



  • 3.  RE: Call-in for Uniface Service using REST API instead WebService

    Posted 09-05-2024 15:42

    Iain,

    One question: is it possible to receive the parameters  in the same way  I put response (using JSON, in form-data/body) to avoid the params in URL?

    Marcelo



    ------------------------------
    Marcelo Martins
    Uniface Consultant
    Vertti Tecnologia Da Informa
    Maringa PR BR
    ------------------------------



  • 4.  RE: Call-in for Uniface Service using REST API instead WebService

    Posted 09-06-2024 04:28
    Yes, they should show in the v_params variable after getting them from $webinfo. Not sure at the moment if this is a list which needs further parsing, but it shouldbe a JSON string, and jsontostruct gives you them in an easy to address format.

    Regards,

    Iain








    Iain Sharp | Head of Technical Services
    Jonas Metals Software
    iains@jonasmetals.com
    tel +44 (0) 114 201 2200
    <http: www.jonasmetals.com=""> www.jonasmetals.com <https: outlook.office.com/bookwithme/user/997d39a6e5de467e8d015be1a0380183@pcisystems.co.uk?anonymous&ep="pcard"> Book Time With Me




  • 5.  RE: Call-in for Uniface Service using REST API instead WebService

    Posted 09-04-2024 08:41

    Hi Marcelo,

    Just a little addendum to Ian answer.

    If you want to be compliant with REST, you'll have to know the HTTP method used by client (GET, POST, PUT, DELETE..). There might be another way to get it, but the solution I found is to parse the $webinfo('WebServerContext') and look for the REQUEST_METHOD.

    For the router, a simple selectcase will mostly cover it.

    Hope it helps



    ------------------------------
    Jean-Marc SALIS
    Mp Services
    Montauban Cedex FR
    ------------------------------



  • 6.  RE: Call-in for Uniface Service using REST API instead WebService

    Posted 09-04-2024 13:11

    I really appreciate your help, Iain and Jean. I´ll implement in this way.

    Thank you, very much



    ------------------------------
    Marcelo Martins
    Uniface Consultant
    Vertti Tecnologia Da Informa
    Maringa PR BR
    ------------------------------