singlesearch returns null instead of empty json

fredrikomfg wrote a month ago: 1

Has the tvmaze ship been abandoned??


tallanvor wrote a month ago: 1

@fredrikomfg wrote:
Has the tvmaze ship been abandoned??

Why aren't you checking the response code?  singlesearch in your example returns 404 which is all you need.

fredrikomfg wrote a month ago: 1

@tallanvor wrote:
Why aren't you checking the response code?  singlesearch in your example returns 404 which is all you need.

One response returns 200 and empty json, and the other one returns 404 null for the same result.

Is it too much to ask that the API responses are consistent?

 

 


tallanvor wrote a month ago: 1

@fredrikomfg wrote:
One response returns 200 and empty json, and the other one returns 404 null for the same result.

Is it too much to ask that the API responses are consistent? 

It is consistent with one view of REST principles. The search endpoint is a collection, so returning 200 with an empty collection if no responses are found is appropriate. For the singlesearch endpoint with a goal of matching a specific resource, returning a 404 is correct.

I can understand your argument since singlesearch is still a search, but ultimately it's semantics and the current functionality is within the spirit of REST design. 

fredrikomfg wrote a month ago: 1

I would have expected 404 when using an endpoint that doesn't exist

Follow up: are you saying the null response is also on purpose? Afaik all other responses with 404 have a JSON payload except this one.


tallanvor wrote a month ago: 1

That I don't know, @david is probably the only one who can answer. I can only say that in my own work, if a call returns a 404, there's no reason to check for anything else. 


david wrote 28 days ago: 2

Pretty much what tallanvor said :-) The search endpoint can return multiple results, so if there are no matches the appropriate output is an empty array. The singlesearch endpoint can only return one result, so if there are no matches the appropriate output is null. I think those are reasonable and pretty standard REST semantics.

fredrikomfg wrote 21 days ago: 1

@david wrote:
Pretty much what tallanvor said :-) The search endpoint can return multiple results, so if there are no matches the appropriate output is an empty array. The singlesearch endpoint can only return one result, so if there are no matches the appropriate output is null. I think those are reasonable and pretty standard REST semantics.

okay, but why don't the other endpoints with 404 response return null?

Try 30 days of free premium.