Instructor: Our next topic are response codes.
So first, let's remember what a response code is.
So, if you remember,
we talked about a typical REST API response
and we looked at this example.
And when analyzing what we are seeing here,
we see that one of the first thing
in the response is the status.
The status in this example is 200
and we already said that 200 represent an okay status.
And of course, there are the other parts of the response.
So basically the responsibility of the response code
is to notify the client about the status of the request,
and specifically did it succeed the request and did it fail?
And if it failed, then why?
And if it failed, what kind of error occurred?
And even more specifically, where was this error?
Now, response codes are extremely important in API
because most clients check
for response code and then act accordingly.
So if the client makes a request
and gets back at 200,
then the client knows that the request succeeded
and it can now go and analyze
the actual content of the request.
But, if some other response code was received
like 400 or 500, then the client usually knows
that there was some kind of problem
and it usually won't even try to analyze the response body.
In addition, monitoring tools,
and we will talk about monitoring later in this course,
often check the response code and report it.
So, from the monitoring tool point of view,
if the monitoring request returned 200,
then everything is fine.
And if some other code was returned
then there is some kind of problem.
In addition,
response codes makes the API easier to use and understand.
So if a developer looks at the API
and he sees the response code,
then he can usually understand immediately
what just happened.
He shouldn't dig into some complicated error messages
and look at stack trace and logging, et cetera.
All he needs to do is to take a look at the response code.
And, response codes are extremely easy to implement,
and unfortunately, they are often overlooked.
A lot of developers aren't even aware
that there is something like a response code
and they always return the same response code
even if it is the wrong one.