View Full Version : JSON Response Format for HTTPProxy on create/update?

16 Aug 2010, 2:13 AM
Can someone point me to where the default JSON format is defined for the response for CRUD operations?

It is maddening that this isn't better documented, I'm just trying to create the server side of these common operations and no amount of google fu is helping me.

I'm guessing it is something along the lines of:

"errors": {"name": "Name is invalid"},
"success": false

But I'm not even sure about that. It also isn't clear what the response code should be on validation errors. Maddening man, does not instill confidence in continuing to use this library.

Andrew Peacock
16 Aug 2010, 3:23 AM
Maddening, true, but this is the one area I've found badly lacking (other than "best practice" advice)

I've just resolved this yesterday using a DirectStore, and am using the following:

My response to the save API is:
"success" => true,
"total" => 1,
"data" => array()

My response to the delete API is:

$output = array(
"success" => true,
"total" => 1,
"data" => Array()

The response to the create API is:

"success" => true,
"total" => 1,
"data" => $itemData

Important point: $itemData is an array that replicates back everything that was sent to the server-side function, plus the value for the ID field. So if JS sends an array like

Then the server should send back

Without that, the row is not created, and cant be saved.

I'm not sure if the "total" item is necessary, I've just put it in so the responses are always consistent.

Hope that helps,

16 Aug 2010, 3:35 AM
Thanks Andrew. I actually have inserts working fine, it is server validation that is giving me fits.

I think it might be because I'm using both a form and a grid backed by a JSONWriter, and the errors from the latter aren't being bubbled up to the former.

I did find some useful articles finally that cover some of that:

Though I'm still not quite finding exactly the combination I want.

Basically I want this example:

Working with server validation as well (and errors propagated to the form). So far I haven't found the right incantations to make it work.


16 Aug 2010, 3:56 AM
The response should be a standard response that the configured Reader will understand, just the same as when you loaded the Store.

It's still the Store making a request.

16 Aug 2010, 4:00 AM
This example shows it well: http://dev.sencha.com/deploy/dev/examples/writer/writer.html


17 Sep 2010, 12:50 AM
I've got a similar issue. I've got a Store with a DataWriter. Attached to this store, like in the example you mentioned, is a FormPanel, that has among the normal form-fields an attached grid so you can select the record to edit in the grid and then edit it in the form fields. The store gets automatically updated when a form field gets changed. The auto-save-enabled Store now sends the create or update request to the server. This works if there are no validation errors. But if there are any, the server sends back something like this:

errors:[{"id":"firstname","msg":"First name must not be empty!"},]
Is it now possible that the validation errors get displayed beside the form fields automatically like in this example (which doesn't use any datawriter, but the traditional form submit function, and beside of this, it uses xml instead of json for the server answer) --> http://dev.sencha.com/deploy/dev/examples/form/xml-form.html.
The alternative way, I guess, would be to catch the validation error sent from the server in the dataproxy exception event and than manually loop through the errors and add them to the form?

Thanks for your help
Dr. Zook

18 Sep 2013, 10:01 AM
Just after creating another post asking for assistance I found a solution -- see: