1
00:00:00,360 --> 00:00:03,930
Instructor: Our next topic are response codes.

2
00:00:03,930 --> 00:00:07,860
So first, let's remember what a response code is.

3
00:00:07,860 --> 00:00:09,480
So, if you remember,

4
00:00:09,480 --> 00:00:12,360
we talked about a typical REST API response

5
00:00:12,360 --> 00:00:14,670
and we looked at this example.

6
00:00:14,670 --> 00:00:17,100
And when analyzing what we are seeing here,

7
00:00:17,100 --> 00:00:19,710
we see that one of the first thing

8
00:00:19,710 --> 00:00:22,500
in the response is the status.

9
00:00:22,500 --> 00:00:24,750
The status in this example is 200

10
00:00:24,750 --> 00:00:29,750
and we already said that 200 represent an okay status.

11
00:00:30,480 --> 00:00:34,307
And of course, there are the other parts of the response.

12
00:00:34,307 --> 00:00:38,040
So basically the responsibility of the response code

13
00:00:38,040 --> 00:00:42,840
is to notify the client about the status of the request,

14
00:00:42,840 --> 00:00:47,840
and specifically did it succeed the request and did it fail?

15
00:00:48,810 --> 00:00:51,810
And if it failed, then why?

16
00:00:51,810 --> 00:00:55,860
And if it failed, what kind of error occurred?

17
00:00:55,860 --> 00:00:59,043
And even more specifically, where was this error?

18
00:01:00,600 --> 00:01:04,980
Now, response codes are extremely important in API

19
00:01:04,980 --> 00:01:07,050
because most clients check

20
00:01:07,050 --> 00:01:09,960
for response code and then act accordingly.

21
00:01:09,960 --> 00:01:12,300
So if the client makes a request

22
00:01:12,300 --> 00:01:14,430
and gets back at 200,

23
00:01:14,430 --> 00:01:17,190
then the client knows that the request succeeded

24
00:01:17,190 --> 00:01:18,930
and it can now go and analyze

25
00:01:18,930 --> 00:01:21,450
the actual content of the request.

26
00:01:21,450 --> 00:01:24,420
But, if some other response code was received

27
00:01:24,420 --> 00:01:28,650
like 400 or 500, then the client usually knows

28
00:01:28,650 --> 00:01:30,690
that there was some kind of problem

29
00:01:30,690 --> 00:01:35,043
and it usually won't even try to analyze the response body.

30
00:01:36,510 --> 00:01:38,160
In addition, monitoring tools,

31
00:01:38,160 --> 00:01:40,680
and we will talk about monitoring later in this course,

32
00:01:40,680 --> 00:01:43,650
often check the response code and report it.

33
00:01:43,650 --> 00:01:46,590
So, from the monitoring tool point of view,

34
00:01:46,590 --> 00:01:49,680
if the monitoring request returned 200,

35
00:01:49,680 --> 00:01:51,300
then everything is fine.

36
00:01:51,300 --> 00:01:53,910
And if some other code was returned

37
00:01:53,910 --> 00:01:56,253
then there is some kind of problem.

38
00:01:57,540 --> 00:01:58,470
In addition,

39
00:01:58,470 --> 00:02:02,220
response codes makes the API easier to use and understand.

40
00:02:02,220 --> 00:02:04,710
So if a developer looks at the API

41
00:02:04,710 --> 00:02:06,480
and he sees the response code,

42
00:02:06,480 --> 00:02:09,060
then he can usually understand immediately

43
00:02:09,060 --> 00:02:10,080
what just happened.

44
00:02:10,080 --> 00:02:13,380
He shouldn't dig into some complicated error messages

45
00:02:13,380 --> 00:02:15,840
and look at stack trace and logging, et cetera.

46
00:02:15,840 --> 00:02:19,770
All he needs to do is to take a look at the response code.

47
00:02:19,770 --> 00:02:23,550
And, response codes are extremely easy to implement,

48
00:02:23,550 --> 00:02:26,610
and unfortunately, they are often overlooked.

49
00:02:26,610 --> 00:02:29,280
A lot of developers aren't even aware

50
00:02:29,280 --> 00:02:31,980
that there is something like a response code

51
00:02:31,980 --> 00:02:35,010
and they always return the same response code

52
00:02:35,010 --> 00:02:36,723
even if it is the wrong one.

