Skip to content
This repository has been archived by the owner on Nov 26, 2024. It is now read-only.

Undefined dataset is returned as 200 response #349

Open
thom4parisot opened this issue Dec 7, 2018 · 3 comments
Open

Undefined dataset is returned as 200 response #349

thom4parisot opened this issue Dec 7, 2018 · 3 comments

Comments

@thom4parisot
Copy link

When I request for https://dev.riskopendata.org/api/dataset/?country=undefined (not an ID) or https://dev.riskopendata.org/api/dataset/?country= (absent ID) or https://dev.riskopendata.org/api/dataset/?country=9999 (unexisting ID), the API returns a 200 response.

  • I expect it to return a 404 when the country does not exist in the database.
  • I expect it to return a 200 with an empty array if the country exists but there is not data.
  • I expect it to return a 200 with array items if the country exists and data exists
@daniviga
Copy link
Contributor

daniviga commented Dec 8, 2018

This is not a bug but was by design. It's a REST API so 404 is sent back if the API url does not exist, not if the resource doesn't.

You are calling a proper endpoint so a 200 is returned. In the json you should then get the error and the reason why (or an empty dataset, depending on the API design). It's an application error what you are looking for, not an HTTP protocol one (which instead raises 404, 500 and so on).

@thom4parisot
Copy link
Author

REST is resource oriented indeed. My understanding, in term of software design, is when requesting a resource (at a given URL):

  • 200: resource is found, resource exists
  • 404: resource is not found, there is nothing matching a primary identifier

Having a response with an empty array and a 200 status code is ambiguous in the situation you describe:

  • resource is found and there is an empty list of element associated to it
  • resource does not exist, an empty list of element is the proof it does not exist

Maybe my expectation is more aligned with api/dataset/:country, country being optional.

If we consider this application, https://dev.riskopendata.org/dataset_details.html?keyds=9999 is the main page requesting data to the api/dataset/; keyds is a requirement. The first 3 URL shared in this issue are derived from actual use case of frontend URL (#350 made me open the issue we are currently discussing).

@nastasi-oq
Copy link
Collaborator

nastasi-oq commented Dec 10, 2018

@oncletom

  • I expect it to return a 404 when the country does not exist in the database.
  • I expect it to return a 200 with an empty array if the country exists but there is not data.

I agree with you if the API offer a specialization of the country as part of the URI, not as a filter as it is now.
If we need this feature we can think to change the API accordingly.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants