0

I have been trying to look for more information about the restful api, I have found many places talk about what request (method and data) to make for retrieve, create, update object in server, but I couldn't find a place that explains what the server side should return. specifically for backbone.js.

I understand for GET method to a "path/:id", the server would probabily return an stringify json object "{id:1,data:aaa}", or an array of json object. but for create, update and delete, I don't know what the server should return so backbone will acknowledge that server has successfully created the object? I found some api does this: create successful returns:

{ "createAt":"2014-1-01 11:59pm"}

or failed returns

{ "error":true}

some api does this:

{"sucess":true} or {"error":true}

What is the result that backbone expect?

Thanks

Evilsanta
  • 1,032
  • 11
  • 18

1 Answers1

1

Backbone generally expects the following:

  • Create should return a JSON representation of the object including an id property with a 201 status (Created).
  • Read should return a JSON representation of the object including an id property with a 200 status (OK).
  • Update should return a 204 status on success (No content).
  • Destroy should return a 200 status on success (OK).
Andrew Hubbs
  • 9,338
  • 9
  • 48
  • 71
  • thank you, that's exactly what I needed. So if the returned is anything different, it would be an error? – Evilsanta Aug 16 '14 at 03:14