Member-only story
REST API Best Practices: Using Proper Status Codes
APIs make the world go round. I’m not exaggerating. So many fundamental things in this world rely on the proper communication and information exchange between computer systems across the globe. For most of this system to system communication, REST APIs have become an industry standard.
This is so significant, that even the term “API Economy” was coined.
Major cloud providers like AWS, expose their services to their global users through a set of API calls.
REST, although over 20 years old, is still the dominant methodology for creating web APIs. Ever though it’s principals are older than many developers implementing them, there still seems to be a lot of bad practice in many APIs that are massively used.
I’ve decided to write a series of articles about REST API best practices, and I will start with a topic that is very important, yet very often not implemented properly — using proper status codes.
Too often have I seen an API return a 500 status code, when the request clearly failed due to a client error, not a server error. Or, even worse, you get a 200 status code, with a response body of
{'error':'bad request'}
Status codes are there to make the API user’s life easier, not more difficult.