Get and send data from existing REST service

Now that I have WEBcore installed, am looking for the best way to adapt to my workflow and have been reading the documentation.  

- Connect to an existing REST webservice (I developed the services and they are quite stable) 
  The REST request has data in the headers for authentication and the URL plus the Body payload tells if the service will use the data or if it has to return data, as in any RESTful service.
- Data sets come in JSON. I would like to use one of the webcore components to pick the JSON and map the fields as a data source so a grid or edits can be filled up without having to parse the JSON field by field, in other words, the delphi way.

- For sending data to the webservice, I would like to take the data fields modified by the user, and have the component take the fields, convert it to a Json and send it in a call to the REST webservice, which based on the endpoint already will know is a request to save data.

So far I  have not found examples or something close to that. and I would really prefer not to have to develop the server side again...

Which are the best components in web core suited for something like this, or at least, to make an asynchronous call where I can retrieve or send a Json  in http requests?  The agility of the SPA and handling everything in the client side is great.  Today am using AJAX with plain javascript for the purpose and hope to be able to convert the project to Webcore using pascal. 

The TWebHttpRequest can be used for this. You can directly set headers via TWebHttpRequest.Headers.

If you use a TWebClientDataSet and the data you receive is a JSON array, you can assign this array to WebClientDataSet.Rows. 
This dataset can be connected via a datasource to your DB-aware controls.
From the dataset events, you could create the desired JSON to send back in case of updates/delete/insert.

Great, that works for me, thank you. 

Hi Bruno,

I know this is an old post but I basically have the same scenario as above.

However, I have a function that sends the JSON returned from my Web Service to a 'Parser' that returns a string of JSON based on the element it is looking for. (It could return a JSONObject as well).

  PAS_Object := TJSONObject.ParseJSONValue(SampleObjectData) as TJSONValue;
  sJson := (ParseJson(PAS_Object.ToString, 'Original'));
  ja := TJSONObject.ParseJSONValue(sJson) as TJSONArray;

An example of the string that is return is as follows:


I can get this data into a TJSONArray but the WebClientDataSet is looking for a TJSArray.

I am not sure how to get my returned data into my WebClientDataSet as I am not sure how to convert my data into a TJSArray.
Do you have any suggestions?

Is this one record you want to add to the dataset?

This example happens to be one record but there could be multiple records returned. Basically, I parse a nested JSON file to get to the particular array of interest. I then want to load the records from the array into a Dataset.

Sorry, Bruno.

That wasn't a very good example of the returned data.
Here is another example:


If it is a JSON array, you can load the JSON array in a dataset via

webclientdataset.Rows: TJSArray

My problem is that my data is in a TJSONArray.
It will not let me load the TJSONArray because it is looking for TJSArray.
Based on the example above, how do I get my data into a TJSArray?

Parse the JSON string with TJSJSON and cast to TJSArray

  ja: TJSArray;
  ja := TJSArray(TJSJSON.parse('myjsonstring'));
1 Like

Thanks, Bruno.

That is exactly what I was looking for.