API - json_api best practice for returning data

I have a Rails application that also has an API. I am trying to follow http://jsonapi.org for a general structure, but I cannot find any recommendations as to when this will happen, without any data. For example, I have an endpoint that looks like this:

https://[root]/api/apps/34/localized_strings?from_date=1330776000

Where from_dateis the unix timestamp, if the server has been updated or new data based on this date value, I return all the data, there are no updates, I do not want to return the data. And I am wondering what is the best way to do this. The current result is as follows:

{
  "data": []
}

Would it be better or more conditional on the basis of http://jsonapi.org to return the status "status" instead: 204in cases where there are no changes or data?

+4
source share
2 answers

According to the specification, an answer representing an empty collection will look like this:

HTTP/1.1 200 OK
Content-Type: application/vnd.api+json

{
  "links": {
    "self": "http://example.com/articles"
  },
  "data": []
}

The server MUST respond to a successful request for a separate resource with a resource object or nullprovided as primary data for response documents.

HTTP/1.1 200 OK
Content-Type: application/vnd.api+json

{
  "links": {
    "self": "http://example.com/articles/1/author"
  },
  "data": null
}
0
source

Just return head :no_content, so the rails will return a 204 status code with empty content

def destroy
  # Destroy stuff

  # Return 204, no content
  head :no_content
end
+2

All Articles