arenanet / api-cdi

Collaborative Development Initiative for Public APIs
252 stars 41 forks source link

Revert error 404 handling (introduced March, 25th) #661

Closed Gedankendreher closed 4 years ago

Gedankendreher commented 4 years ago

When requesting a bunch of items or achievements, an error 404 is returned when one or more ids could not be fetched. Apart from the fact that the error 404 commonly is used for a completely different context (the endpoint was not found), the error is totally wrong and working around it introduces extra load and delays due to additional queries.

In the past, having a non-resolvable reference ID in the query resulted in a list with the resolvable items at least. This is great - after exactly one query I got the data available from the service and was able to handle the missing ids locally. Now, if there is one unresolvable ID within the query, the API returns 404 (all ids are invalid). This not true. Removing the unresolvable IDs only results in the expected result - a list of all resolved ids.

Now, there is no benefit in asking for more than one ID per query as the service just lies because of a (usually small) subset. To list the content of a bigger bank for example, this could easily multiply the number of required queries by something hundred. Other strategies could deal with it in 20, 30 queries but this still consumes much more resources than the one query...

The API should be consistent for types (achievements, items, titles, minis, outfits etc) and:

  1. Return status code 200 if all reference IDs can be resolved.
  2. Return status code 206 (partial content) when one or more IDs aren't resolvable. This could allow the client to activate an internal processing to deal with unresolvable ids.
  3. Technically, "no resolvable ids" is just a very special case of partial content. If really a differentiation is required, status code 204 should be returned. Personally, I don't see a reason for marking this case with an extra code as handling wouldn't be different from a clients view...
Eearslya commented 4 years ago

Can you provide some example URLs that produce a 404? I've just tested those endpoints, and they do return 206 if one or more of the IDs is invalid.

https://api.guildwars2.com/v2/items?ids=6,24,999999,5000

To my knowledge, the API already responds 200 to a full success, and 206 to a partial.

Gedankendreher commented 4 years ago

I just run my junit tests and wasn't able to reproduce the issue. My work arounds for achievement and items haven't been triggered at all. I worked on achievements and progress a couple of days ago so this could be something temporary.