Skip to main content

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

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

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

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

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

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

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

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

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

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
------------------------------
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
www.jonasmetals.com Book Time With Me