[ckan-dev] Confused on response['success'] and HTTP status codes with empty results
Ian Ward
ian at excess.org
Thu Mar 28 14:28:12 UTC 2013
Hi Daniel,
Not directly related to your question, but I've been using ckan from
within a plugin and most of my code looks like:
try:
organization = get_action('organization_show')(context, {
'id':org['id'].lower()})
response = get_action('group_delete')(context, organization)
except NotFound:
pass
Is is possible for your new libckan api to look like this too?
On Thu, Mar 28, 2013 at 5:12 AM, Daniel Graziotin <dgraziotin at task3.cc> wrote:
> Hi,
> 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
> }
> ---
>
> 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 was a RESTful API it would make sense. However, in that case I would do something like GET /api/tags/12345 and expect a HTTP 404 status code when such result was not existing.
>
> Not criticizing the architectural choices here. I am just trying to do some sense making in order to build a better libckan.
>
> Cheers,
> --Daniel Graziotin
>
>
>
> _______________________________________________
> ckan-dev mailing list
> ckan-dev at lists.okfn.org
> http://lists.okfn.org/mailman/listinfo/ckan-dev
> Unsubscribe: http://lists.okfn.org/mailman/options/ckan-dev
More information about the ckan-dev
mailing list