GFDRR / open-risk-data-dashboard

Repository for the Open Data for Resilience Index, a website to track and improve the state of Open Data for Resilience worldwide.
https://index.opendri.org
GNU Lesser General Public License v3.0
23 stars 8 forks source link

Undefined dataset is returned as 200 response #349

Open thom4parisot opened 5 years ago

thom4parisot commented 5 years ago

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.

daniviga commented 5 years ago

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 commented 5 years ago

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

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

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 commented 5 years ago

@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.