Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrongly returns a 404 status code #69

Closed
neonwired opened this issue Jul 8, 2016 · 2 comments · May be fixed by noelenwenede/postcodes.io#5
Closed

Wrongly returns a 404 status code #69

neonwired opened this issue Jul 8, 2016 · 2 comments · May be fixed by noelenwenede/postcodes.io#5

Comments

@neonwired
Copy link

if you go to http://api.postcodes.io/postcodes/s62%205ty it correctly returns a result of 'postcode not found' but has a 404 status code. Not sure if this is just a mistake or a misunderstanding of what a 404 status code means.

If the communication with the server was successful, regardless of whether results were found it should return a 200 status code.

@cblanc
Copy link
Member

cblanc commented Jul 9, 2016

Returning 404 is the intent

This particular API was created when "RESTful" interfaces were in vogue. Although there is no formal spec for designing these types of APIs, my understanding is that it's generally considered a good idea to make full use of the available range of HTTP status codes to accurately relay information about the nature of a request.

When requesting a resource (like in this case, a postcode) it's common to return a 404 response code if that resource does not exist. A good indicator that you're dealing with a resource is if the URI looks something like /resource/:resource_id

I don't think postcodes.io is in the minority here, most HTTP API's designed within the last ~5 years take a similar approach. The Ruby on Rails framework, which is built around RESTful ideas, returns 404 by default for a non existent resource. Likewise (afaik) many popular REST API's like Twitter and Stripe exhibit similar behaviour.

However, if you were performing a query like /postcodes?q=s625ty I'd agree with you that a 200 status code should be returned for both a populated and empty result set.

It's only /outcodes/:id and /postcodes/:id that exhibit this behaviour as they are considered as resources. All other "query-like" methods will return the 200 status code you're expecting.

@neonwired
Copy link
Author

Sounds right.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

2 participants