4D and REST calls

I am having the annoying young kids from the web development team breathing down my neck and i need some quick advice. We are using our 4D application as the hub for lots of central data and running multiple web developments that call our central application. So far we have been using a very lightweight SOAP protocol where we basically wrap json files in the SOAP XML envelope. Now the web guys are starting to call for a even more lightweight REST protocol. The reason they give me is that their javascript libraries they are using is starting to phase out the SOAP support.

I have done some very fast investigations in this matter. We just basically need the full data in a POST command. We get the data in the “On WEB CONNECTION” method and all data seems to be in header/content parameter. But this parameter is limited according to the manual to 32Kb.

So anyone. what is my options?

  1. Force them web developers to continue to work with SOAP with the risk of their libraries getting outdated?
  2. Does 4D mobile give me this?. (We have tried that before and had a pretty bad experience with the license system )
    3 Is there any other way to respond and receive data from a POST request using the APPLICATION/JSON parameter?


The “current” way is to use WEB GET VARIABLES for the query parameters.



WEB GET HTTP BODY to get the body.


There are more commands in the same theme for other purposes.

Hope that helps.

Best regards


  1. no. Force your 4D team to go REST. SOAP was state of the art years ago, it is heavy to decode (at least for JavaScript), heavy to transfer (compared to REST), difficult to read (at least for me) and sadly enough went far away from the original idea to become an open standard.

  2. no. 4D Mobile is the gateway between 4D and Wakanda (while Wakanda is providing a REST API on top of a data model which uses your 4D data as source).

  3. many ways. Endless ways. We had many examples. Goto kb.4d.com and search for Ajax. You find a huge amount of hits. The oldest one was my first steps with REST, named “Rich Internet Clients – First Steps with AJAX”, written for 4D version 2004 in 2006…
    While the used JavaScript frameworks don’t exists anymore - the 4D part would still work, even there are these days better ways to do it.

One of my personal favorite ways is to use PROCESS 4D TAGS. Using a smart template, which has all the logic inside and giving as result JSON. Easy to code, easy to maintain. Easy to have several versions (just duplicate the text/template files).

Another way is to use code.

If you ever visited a 4D World Tour, you have our invoice example.

If not, use any other database with a table named CLIENT and at least a field “Name” and “City”.
Create a new method and copy&paste this content:

<code 4D>
ARRAY TEXT($namearray;0)
ARRAY TEXT($valuearray;0)
WEB GET VARIABLES($namearray;$valuearray)
if(size of array($namearray)>0)
Case of
: ($namearray{1}=“name”)
: ($namearray{1}=“city”)
End case
$result:=$sel.toCollection("";dk with primary key+dk with stamp)
end if

$answer:=JSON Stringify($result)
WEB SEND text($answer;“application/json”)
</code 4D>

Allow this method to be used via 4DAction (method property), use a web browser and enter:

You will get something as:
{"__KEY":1,"__STAMP":3,“ID”:1,“Name”:“Alpha Astral Animations”,“Address”:“Ullman Drive (82)”,“Numbers”:{“Phone”:"(823) 312-4824",“Mobile”:"(554) 241-6830",“Fax”:"(056) 502-2770"},“City”:“Georgetown”,“State”:“Delaware”,“Zip_Code”:“19947”,"_Phone":"","_Mobile":"","_Fax":"","_Email":"","_Web_Site":"",“Logo”:"[object Picture]",“Contact”:“Charlotte Sinclair”,“Comments”:“To recontact”,“Total_Sales”:0,“Country”:“USA”,“Discount_Rate”:0,“eAddresses”:{“eMail":"charlotte.sinclair@alphaastralanimations.com”,“WebSite”:“www.AlphaAstralAnimations.com”},“Optional_Data”:{“CEO”:“Larry Rybard”,“Employees”:124}},{"__KEY":2,"__STAMP":3,“ID”:2,“Name”:“Alpha Bart Computing”,“Address”:“Lehigh Square (109)”,“Numbers”:{“Phone”:"(359) 903-5994",“Mobile”:"(799) 621-4540",“Fax”:"(467) 725-4056"},“City”:“Woodbridge”,“State”:“Connecticut”,“Zip_Code”:“6525”,"_Phone":"","_Mobile":"","_Fax":"","_Email":"","_Web_Site":"",“Logo”:"[object Picture]",“Contact”:“Charlie Weaver”,“Comments”:"To …

Try the same for city, etc.

Thanks to ORDA, creation of REST answers is very simple.
The first parameter of .toCollection() allows to select which fields you want to expose.
To use this example, you need v17 and you need to enable object notation.

Note: this is quick & dirty code. No error checking. It support only one query criteria. No password control. Just a show case.

Thank you guys. This was exactly what i needed to get ahead. Perfect!