Subscribe for automatic updates: RSS icon RSS

Login icon Sign in for full access | Help icon Help
Advanced search

Pages: [1]
  Reply  |  Print  
Author Topic: JSON based Web Service  (Read 24784 times)
Anderson P.
Posts: 82


« on: May 21, 2014, 02:17:32 pm »

Is it possible to make a JSON based web service in Genero instead of XML?
Reuben B.
Four Js
Posts: 1116


« Reply #1 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

Product Consultant (Asia Pacific)
Developer Relations Manager (Worldwide)
Author of https://4js.com/ask-reuben
Contributor to https://github.com/FourjsGenero
Anderson P.
Posts: 82


« Reply #2 on: May 22, 2014, 01:27:18 pm »

Do you have an example that i can base in?
Anderson P.
Posts: 82


« Reply #3 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?
Laurent G.
Four Js
Posts: 114


« Reply #4 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.

* datasyncServer.4gl (9.54 KB - downloaded 1712 times.)
* datasyncClient.4gl (4.16 KB - downloaded 1725 times.)
Anderson P.
Posts: 82


« Reply #5 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. 
Pages: [1]
  Reply  |  Print  
 
Jump to:  

Powered by SMF 1.1.21 | SMF © 2015, Simple Machines