1
00:00:00,300 --> 00:00:01,133
Instructor: And now,

2
00:00:01,133 --> 00:00:05,700
let's talk about the structure of REST API Response.

3
00:00:05,700 --> 00:00:09,480
So, in the response also, we have some components.

4
00:00:09,480 --> 00:00:12,420
First, the Status Code.

5
00:00:12,420 --> 00:00:14,670
The Status Code is a number,

6
00:00:14,670 --> 00:00:17,490
a three digit number, that represent

7
00:00:17,490 --> 00:00:20,700
whether the request succeeded or not.

8
00:00:20,700 --> 00:00:22,413
And if not, what was the problem.

9
00:00:23,280 --> 00:00:25,470
After that, again, Headers,

10
00:00:25,470 --> 00:00:28,080
some Meta-data about the response.

11
00:00:28,080 --> 00:00:28,920
And,

12
00:00:28,920 --> 00:00:30,960
last is the Body.

13
00:00:30,960 --> 00:00:32,640
In this case, as you can guess,

14
00:00:32,640 --> 00:00:36,120
the body contains the contents of the response.

15
00:00:36,120 --> 00:00:38,190
As we will see later in this course,

16
00:00:38,190 --> 00:00:39,390
the body in the response

17
00:00:39,390 --> 00:00:41,790
also liking the request is optional,

18
00:00:41,790 --> 00:00:43,593
and we don't always have a body.

19
00:00:44,640 --> 00:00:48,540
And, here is an example of a REST API Response

20
00:00:48,540 --> 00:00:50,670
and let's look closely at it.

21
00:00:50,670 --> 00:00:54,450
So, this is the Status Code, in this case 200.

22
00:00:54,450 --> 00:00:57,600
200 in the HTTP protocol means, okay,

23
00:00:57,600 --> 00:00:59,763
meaning the request succeeded.

24
00:01:00,600 --> 00:01:01,833
Next, are the Headers.

25
00:01:03,120 --> 00:01:05,400
And, last is the Body.

26
00:01:05,400 --> 00:01:08,040
In this case, the body contains the data

27
00:01:08,040 --> 00:01:10,050
about the resource we asked for.

28
00:01:10,050 --> 00:01:11,940
Remember, that in our example

29
00:01:11,940 --> 00:01:14,940
we used order number 17 as an example resource.

30
00:01:14,940 --> 00:01:19,470
So, here is a representation of the resources state.

31
00:01:19,470 --> 00:01:23,100
In this case, the representation is a JSON.

32
00:01:23,100 --> 00:01:26,400
And you can see in the order number 17, the order date

33
00:01:26,400 --> 00:01:29,733
and what items are included in this order.

34
00:01:30,600 --> 00:01:34,590
We said earlier that the response is usually represented

35
00:01:34,590 --> 00:01:35,670
as JSON.

36
00:01:35,670 --> 00:01:37,530
But this is not always the case.

37
00:01:37,530 --> 00:01:41,010
And sometimes you will use maybe some other formats,

38
00:01:41,010 --> 00:01:43,020
like XML or HTML.

39
00:01:43,020 --> 00:01:47,040
But, it's important to note that these are rarely used.

40
00:01:47,040 --> 00:01:49,050
You should always try to use JSON,

41
00:01:49,050 --> 00:01:51,603
unless dictated other by the client.

