APIs Aren't Just For Devs Pt. 5 - HTTP Response Codes
I know in my last post; I mentioned I would take you through real life examples of using public APIs using Postman. It dawned upon me as I was preparing the blog, that I never discussed HTTP response codes. Gah. These are pretty important in understanding if your API endpoint is giving you what you require to make the request successful!
If you're landing on this blog first, know that I have 4 blogs that lead us up to here. Check them out below:
So, what are HTTP response codes? HTTP response codes are three-digit numbers that a web server sends back to your web browser or client when you make a request to a website. They provide information about the status of your request and tell you whether everything went smoothly or if there was a problem.
Let's break them down into different groups to make it easier to understand:
1xx - Informational Response: These codes indicate that the server received your request and is continuing to process it. You don't often see these in practice.
2xx - Success: When you see a 2xx response code, it means your request was successful, and the server has successfully processed it. The most common one is:
200 OK: This means everything went fine, and the server is sending back the data you requested.
3xx - Redirection: These codes tell your browser that the requested resource has moved to a different location. So, your browser needs to redirect to the new location to fetch the data. The most common ones are:
301 Moved Permanently: The resource has moved permanently to a new URL.
302 Found/Redirect: The resource has temporarily moved to a different URL.
4xx - Client Errors: These codes indicate that there was an issue with your request. The problem is usually on your end (the client). Some common ones are:
400 Bad Request: Your request was malformed or had invalid syntax.
404 Not Found: The server couldn't find the requested resource.
5xx - Server Errors: These codes are returned when there's an issue on the server-side. It means the server couldn't fulfill your request due to some problem on their end. Some common ones are:
500 Internal Server Error: Something went wrong on the server's side, causing the request to fail.
502 Bad Gateway: The server acting as a gateway or proxy received an invalid response from the upstream server.
If you want to read more in depth about these response codes and what they mean, bookmark the Wikipedia entry: List of HTTP status codes - Wikipedia
Remember, whenever you access a website or web service, these response codes play an essential role in communicating the status of your request. They can help you or developers understand what's happening and diagnose any issues that may arise during web browsing or application interactions.