WEBVTT

0
00:00.270 --> 00:09.870
Now that we've added a URL for our feed API let's go ahead and test it in the browser. Open up the

1
00:09.900 --> 00:17.190
terminal or git bash window and make sure you've activated the virtual environment and that your development

2
00:17.190 --> 00:26.460
server is up and running. Then open up google chrome and ensure that our authentication token is still

3
00:26.460 --> 00:34.080
set in the mod headers chrome extension and head over to the URL of our API which is 127.0

4
00:34.200 --> 00:40.440
0.0.1 : 8000 forward slash API.

5
00:40.440 --> 00:47.940
Once the page loads you can see that there is a new feed item added to the list of our API root.

6
00:48.000 --> 00:52.310
This is the feed API that we created previously.

7
00:52.460 --> 00:58.350
So click on that and it should take you to this empty feed list.

8
00:58.350 --> 01:05.340
Now this is where we can create and modify status updates for our user.

9
01:05.610 --> 01:15.810
So if we add a new status text and we'll just write test status for this one and hit post you can see

10
01:15.810 --> 01:23.700
that it goes and creates a new status update for us and returns the object in the browser. So you can

11
01:23.700 --> 01:30.090
see that it created a new object with the I.D. one and it assigned it to the user profile one because

12
01:30.090 --> 01:35.940
that is the user that we are currently authenticated with.

13
01:35.970 --> 01:36.380
Okay.

14
01:36.410 --> 01:38.730
So what if we wanted to modify this.

15
01:38.730 --> 01:44.550
Well let's test the HTTP put and patch methods on this API.

16
01:45.390 --> 01:53.580
So add the primary key ID which is the ID field of the object that was just created to the end of

17
01:53.580 --> 01:56.580
the URL of our feed endpoint and hit enter.

18
01:56.760 --> 02:05.610
This will take us to the page where we can modify or perform HTTP put or HTTP patch requests

19
02:05.820 --> 02:07.540
on our object.

20
02:07.590 --> 02:08.820
So if we want to perform a put

21
02:08.850 --> 02:12.060
we simply just modify the text here.

22
02:12.330 --> 02:17.770
So let's say we change this to test status to and hit put

23
02:17.790 --> 02:24.630
you can see that the status text changes for this object if you want to test the patch you have to do

24
02:24.630 --> 02:27.360
this in the raw data tab.

25
02:27.360 --> 02:29.140
So we'll remove all of these

26
02:29.140 --> 02:37.950
read only fields and then we'll just leave the status text and we'll just change this to test status 3 and

27
02:37.950 --> 02:39.040
we'll hit patch.

28
02:39.060 --> 02:44.520
Make sure that you remove the trailing comma here because otherwise it will be an invalid json object

29
02:44.520 --> 02:46.980
and you'll get a validation error.

30
02:47.010 --> 02:54.900
So once as all correct hit patch and you can see that it updates our profile object.

31
02:55.410 --> 02:58.050
Okay so this all appears to be working.

32
02:58.050 --> 02:59.990
Let's try and delete our object.

33
03:00.000 --> 03:06.750
So hit delete and then this will make an HTTP DELETE request to our object and it will remove the

34
03:06.750 --> 03:07.350
object.

35
03:07.440 --> 03:12.190
And then if we go back to the root of the feed you can see that there are no items here.

36
03:13.170 --> 03:16.320
Okay so this is when we're authenticated.

37
03:16.410 --> 03:20.910
What happens if we try and create an object when we're not authenticated.

38
03:20.940 --> 03:26.970
So let's uncheck the authorization in the mod headers chrome extension and then we're going to go ahead

39
03:26.970 --> 03:34.170
and just refresh the feed page and let's create a new status, click on the HTML form and we'll

40
03:34.170 --> 03:39.180
just put some test status text and then hit post.

41
03:39.270 --> 03:42.320
You can see that because we are not authenticated

42
03:42.390 --> 03:45.900
we got an uncaught exception raised.

43
03:45.930 --> 03:53.280
So this is an error and this is because you cannot assign the anonymous user object to the user profile

44
03:53.280 --> 03:54.520
of the feed item.

45
03:54.540 --> 04:01.260
So this indicates that there are a few more changes that we need to make to our API view set in order

46
04:01.260 --> 04:07.380
to handle this case and ensure that we never see an error like this in our API.

47
04:07.380 --> 04:10.140
So we're going to be doing that in the future videos.

48
04:10.200 --> 04:14.340
That's how you test the feed in the browser and I'll see you in the next video.