[ckan-dev] Confused on response['success'] and HTTP status codes with empty results

Sean Hammond sean.hammond at okfn.org
Mon Apr 1 20:42:02 UTC 2013


> I understand that the new API is abandoning the idea of a RESTful
> service in favor of a RPC-like architecture over HTTP requests.  I am
> fine with this, just take this in mind in what follows.
> 
> Given that CKAN Action API is not RESTful: when there are no results,
> why do - some methods return HTTP 200, response['success']: true and
> response['results']:[] - some other methods return HTTP 400,
> response['success']: false and a not found error
> 
> Example:
> 
> Searching for tags with zero results --- http --json
> http://beta.ckan.org/api/action/tag_search q=LOL
> 
> HTTP/1.1 200 OK [...]
> 
> { "help": [...], "result": { "count": 0, "results": [] }, "success":
> true } ---
> 
> Trying to retrieve a non-existing tag by id --- http --json
> http://beta.ckan.org/api/action/tag_show id=12345 HTTP/1.1 404 Not
> Found [...]
> 
> { "error": { "__type": "Not Found Error", "message": "Not found" },
> "help": [...] "success": false } ---

I think the API has several problems with inconsistent and sometimes
just plain incorrect behaviour, both in terms of what it returns and
also sometimes what parameters it expects. There is a pull request to
tidy up at least soe of the problems, though I'm not sure if it
addresses your issue in particular:

https://github.com/okfn/ckan/pull/473

> Given that this is not RESTful, why isn't the second one a successful
> request - e.g., a valid request - however with no results?  If this

I partially agree. The API is supposed to always return HTTP status
code 200 OK, according to the docs:

http://docs.ckan.org/en/latest/api.html

so it should not be returning a 404. But in your tag_show example you
asked CKAN to show a tag that doesn't exist, since CKAN obviously cannot
show you this tag successfully it _should__ be returning "success":
False with something to the effect of "that tag doesn't exist" in the
error field. Whereas in your tag_search example, tag_search "returns a
list of tags whose names contain a given string", if there are no tags
that match the given string CKAN can still fulfill the request
successfully, so in this case "success": True and "result": [] seems
right to me.

seems correct, rather than "success": True
and "result": [].




More information about the ckan-dev mailing list