mysociety / mapit

A web service to map postcodes to administrative boundaries and more
Other
269 stars 88 forks source link

API returns HTML for 404s #421

Open torotil opened 9 months ago

torotil commented 9 months ago

The API documentation says:

All calls return JSON, and you can generally get an HTML representation by adding .html on the end.

and

Whenever an error is returned from MapIt, it is as a dictionary with an error key …

but for example https://mapit.mysociety.org/postcode/F-54110 returns a HTML page.

dracos commented 9 months ago

It does return JSON for something that looks like a postcode but doesn't exist. We should probably have a default fallback for the endpoint locations to JSON, just for consistency, though we hope API users will do what they can to reduce unnecessary API calls being made. In this case, it hasn't actually reached the postcode endpoint with that URL, because it hasn't got past the basic check in the router, hence it being treated as a normal web page. The API does sort of assume you are doing some minimal form of checking of the data you're going to send before being sent (e.g. stripping out non-alphanumerics, perhaps even checking it's the right format for a postcode ideally).