Question

In my Cappuccino frontend I'm using Ratatosk to make queries to a RESTful JSON-based API.

When I create a new resource with

[myNewResource ensureCreated];

my backend returns the status code 201 and a Location header with the URI of the newly created resource. The response body is empty. As far as I know, that's the way a REST API should react to successful POST requests.

But upon receiving the response, Ratatosk calls

- (void)connection:(CPURLConnection)aConnection didReceiveData:(CPString)data

(in WLRemoteLink.j) and tries to decode the response body. This throws an error because the response body is empty. As a consequence, the request is repeated infinitely.

How should I go about this? Am I supposed to return the whole resource in the response body?

EDIT:

Returning the ID in the response solved the problem, like

{"id":1}
Was it helpful?

Solution

Ratatosk expects the status code 204 (no content) if the response is to be empty. Otherwise it expects the full representation of the resource which was just created (which it uses to populate server side dynamic properties locally like created_at).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top