3

I am looking for a good meaningful discussion of why people feel like it is a good idea that RESTful web services hijack HTTP response codes and assign meanings to them in the context of the given API. My intuition revolts against it: it feels that HTTP is serving as the transport layer protocol here and why would I leak my API concepts into the transport layer? Yes, I understand that HTTP is application layer in the 27 layer diagram, but layering is relative. For my API HTTP is a transport.
Now people say that otherwise error handling can't be standardized. But REST doesn't really standardize it either. We can feel good about 401 and 404 messages being somewhat intuitive, but that's bout it. What it really does is makes it harder to differentiate between and API error and API server not being there/client not pointing to the right place etc.

1 Answer 1

2

Which of those scenarios you think would bring better outcomes:

  • Re-Using HTTP status codes like 200-OK, 404-Not found, 500-Error, etc for an API layer to mean similar responses that are mostly guaranteed to be used in a standard way across all RESTful API vendors

OR

  • API vendors return 200-OK, and the message body contains custom response envelopes or bodies to mean similar things (like Not Found, and Error)

First scenario allows also for developing standard libraries to communicate with those APIs where the second scenario means every API is a unique case and things like error handling, caching, etc cannot be done in a standard way.

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

3 Comments

I'm failing to imagine that standard library for talking to multiple different APIs where you don't care about looking at the response body and are completely satisfied with the http status code. Caching is a valid point of course, but can be more or less easily handled with the response headers.
For web clients, In most JavaScript libraries that encapsulate XmlHttpRequest (Ajax) like Promises for example, they use HHTP status codes to interpret the general success, failure situations (200x to mean success for example) and this makes life simpler to API consumers as a standard.
sounds like trading off correctness to make one of the use cases easier.

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.