0

I have a scenario where my API application contacts external datasources and for this particular example, my API requests a list of colours from the external datasource. Sometimes the datasource doesnt have these colours and returns a plain text response of "There are no options to display" with a HTTP status code of 200 OK.

What i am wondering is what status code i should return to the client which is consuming my API in this scenario? A 404 not found or 204 no content...? Im not sure what would fit best.

Thanks

1 Answer 1

1

Is it valid not to return any colours? In which case your original 200 may be the right status code to use.

204 is normally used to indicate success, but the client need not update any information it holds; deleting or updating a resource for example are valid times to use 204.

404 seems wrong if the same URL is being accessed, in your scenario it sounds like the state of resource may change overtime (and it may be empty), but it always exists.

Sign up to request clarification or add additional context in comments.

3 Comments

So what your saying is that a 200 could be right if its valid that no colours are returned. I think i will go with that then. Thanks for pushing me in the right direction.
In a nutshell, yes :-), glad you found the answer helpful!
yep, 200 with empty list of results is the right approach imho

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.