Four Js Development Tools Forum

Discussions by product => GWS => Topic started by: Anderson P. on May 21, 2014, 02:17:32 pm



Title: JSON based Web Service
Post by: Anderson P. on May 21, 2014, 02:17:32 pm
Is it possible to make a JSON based web service in Genero instead of XML?


Title: Re: JSON based Web Service
Post by: Reuben B. on May 21, 2014, 11:51:40 pm
Yes.

If you are looking for ...

com.HttpServerRequest.readJSONRequest()
com.HttpServiceRequest.sendJSONResponse()

com.HttpRequest.doJSONRequest()
com.HttpResponse.getJSONResponse()

... to match the XML equivalents

com.HttpServerRequest.readXMLRequest()
com.HttpServiceRequest.sendXMLResponse()

com.HttpRequest.doXMLRequest()
com.HttpResponse.getXMLResponse()


... they aren't there.  The technique is to use the Text methods

com.HttpServerRequest.readTextRequest()
com.HttpServiceRequest.sendTextResponse()

com.HttpRequest.doTextRequest()
com.HttpResponse.getTextResponse()

and use the JSON objects methods to turn a JSON Object into a string and vice versa.

Perhaps we should add such JSON methods

Reuben


Title: Re: JSON based Web Service
Post by: Anderson P. on May 22, 2014, 01:27:18 pm
Do you have an example that i can base in?


Title: Re: JSON based Web Service
Post by: Anderson P. on May 22, 2014, 02:21:38 pm
We always used the com.WebOperation.CreateDocStyle method to generate a web service using a record attribute, so I'm not quite sure how to use this methods you proposed... Or is there some way i can use this CreateDocStyle method to generate an text web service instead of a XML web service?


Title: JSON based Web Service
Post by: Laurent G. on May 29, 2014, 06:03:11 pm
See attached a small sample I used to do basic testing. Some of the business logic functions on the server side might not work properly but this will give you a general ideal on the client/server exchange and you can use this code as a frame/start

For RESTful type of web services, you currently only can manual write them, no code generation tool is available yet

For the JSON part, we have new methods that allow you to map Objects or Arrays to Genero 4gl records.


Title: Re: JSON based Web Service
Post by: Anderson P. on May 29, 2014, 06:36:36 pm
Laurent, that was an excellent example. Thank you very much!

Florencia also sent me an example, merging both gave me exactly what i needed.

It is indeed very easy to accomplish a REST web service with JSON in Genero, once you get the right commands.

Thank you for your attention.