WEBVTT

00:01.070 --> 00:01.610
Okay.

00:01.760 --> 00:08.060
In this video, I will show you how to use another tool for our API development.

00:08.060 --> 00:09.910
And that tool is Postman.

00:09.920 --> 00:16.370
I think it's most popular API development tool available on the market.

00:16.400 --> 00:20.450
Now it is free so you can use it as you like.

00:20.450 --> 00:27.440
And at the beginning I think Postman was ah, just a chrome extension, but now it's a standalone application.

00:27.440 --> 00:33.920
So what you need to do is you go to the product and you have Postman here.

00:35.170 --> 00:40.690
And then you can download the application and it's as simple as just next, next, next, next, and

00:40.690 --> 00:42.940
install that on your operating system.

00:42.940 --> 00:48.010
So once you will have the postman installed on your computer.

00:53.170 --> 00:59.790
Now Postman is opening and we have a data interface available.

01:00.900 --> 01:09.900
So what we can do here, we can do similar things as we've done in our previous video using this interface.

01:09.900 --> 01:13.650
So if I will come back here to the books.

01:15.330 --> 01:18.560
You can see that is the object I saw there.

01:18.570 --> 01:27.210
If I copy that URL now, Ctrl C and I'll go to my postman and then I will paste it here.

01:27.210 --> 01:36.180
So basically what we are doing is we are trying to fetch that data from, from that URL and here I can

01:36.180 --> 01:37.980
select the method I would like to use.

01:37.980 --> 01:41.730
I will keep it to get here and then I will send.

01:43.260 --> 01:52.020
It looks what what I have here in the in the output basically it's what I had in the previous page.

01:52.020 --> 01:57.690
But this time this is a typical Json text format available for me.

01:57.690 --> 02:04.350
This is also based on serializer as we had it before and we see all that information.

02:04.350 --> 02:05.280
So let's.

02:06.170 --> 02:09.800
Come back here and let's add more.

02:10.100 --> 02:17.270
If we go to the models, we have title description, price we can do, publish is published and then

02:17.270 --> 02:18.080
cover.

02:18.800 --> 02:20.810
We can leave the cover for now.

02:20.960 --> 02:24.590
So we'll do this published.

02:25.620 --> 02:27.390
And also we can do.

02:29.110 --> 02:31.180
So publish is published.

02:31.840 --> 02:35.950
If will add it now and then I will come back to the postman and refresh it.

02:35.980 --> 02:43.510
You can see I have all that information available for each book in our database.

02:43.510 --> 02:45.280
So that's one object.

02:45.280 --> 02:46.930
And here is another one.

02:46.930 --> 02:53.410
This brackets square brackets means beginning of array and add of array.

02:53.420 --> 02:56.590
So that's what is available through serializer.

02:56.590 --> 02:58.930
And this is what we use as a get.

02:59.110 --> 03:09.070
What I can also do is I already mentioned that before that Django automatically include ID in our records.

03:09.070 --> 03:13.870
So what I can do is I can also include that ID, so I will save it.

03:14.950 --> 03:17.800
And if will come back here and refresh it, send it again.

03:17.800 --> 03:21.370
You can see it is a part of this output.

03:21.970 --> 03:28.810
So this is the method that we register in our router.

03:28.820 --> 03:36.540
We'll come back to the URLs here and we can see this is register books with a view set.

03:36.550 --> 03:42.100
So this view set brings more than just a list of the items in the database.

03:42.190 --> 03:47.590
It has much more things built in and I will show you what other things are available.

03:47.590 --> 03:57.700
So if we have ID one, I know the books, we have books with ID one and then I can pass one at the end

03:57.700 --> 04:00.460
of the URL and then slash.

04:00.460 --> 04:07.930
So basically books will give me all the list and if I will pass as an extra parameter the ID of the

04:07.930 --> 04:09.880
books, then I will send it.

04:09.880 --> 04:14.690
You can see only one record is returned with the ID one.

04:14.720 --> 04:21.380
I can also do two, which is the second book with the ID two.

04:21.380 --> 04:24.350
So basically that's already done for us.

04:24.350 --> 04:28.940
We don't need to set up or configure anything using Methodget.

04:28.970 --> 04:33.020
We can have both if I will have it without that ID.

04:34.490 --> 04:35.510
The whole list.

04:36.260 --> 04:39.710
We can pass ID and get the certain record.

04:40.160 --> 04:42.020
So what else is available?

04:43.010 --> 04:44.480
We can do post.

04:45.530 --> 04:50.420
So if I will post to the books, we can post.

04:52.090 --> 04:53.170
Using.

04:54.060 --> 04:59.190
Like this form here and I will pick body and then this form.

04:59.190 --> 05:01.200
Or we can do form data.

05:01.770 --> 05:09.810
But what we need to do, we need to pass title and let's say our book will be Twilight.

05:10.840 --> 05:18.580
To just stay him in the same topic as we have here and picking the post here and clicking on send,

05:18.580 --> 05:27.490
I will take this value and I will send it for this URL and this URL accept will accept the post as well.

05:27.490 --> 05:31.360
So if I will send it, you will see it's not going to go through.

05:32.610 --> 05:34.440
Actually it went through.

05:35.040 --> 05:40.880
And because we set up our model to have the default value for everything.

05:40.890 --> 05:47.250
So at the moment we have another record and then we have title return it to us.

05:47.250 --> 05:53.790
So if I will come back from the post to get, and then I would like to see a list of our books in the

05:53.800 --> 06:00.060
system I can go send and I can see here I have three books in the system now.

06:00.060 --> 06:04.110
So what else is available for us?

06:04.590 --> 06:08.190
We can do put, for example, put.

06:08.220 --> 06:09.990
It's not going to work on books.

06:09.990 --> 06:14.270
We need to specify for which record we will use the put method.

06:14.280 --> 06:15.270
Let's say three.

06:15.300 --> 06:23.310
Three is the ID of the the book we've just created here so we can see here three and put will basically

06:23.310 --> 06:26.460
change the our record in database.

06:26.460 --> 06:32.320
So post create a new record like we did here and the put will change it.

06:32.320 --> 06:38.650
So we still need to pass some information so we'll pass it with the body and then I can title Let's

06:38.650 --> 06:41.230
do Twilight Saga.

06:41.740 --> 06:49.090
I don't know something and probably there is a lot of different Twilight saga anyway, if I have put

06:49.090 --> 06:56.350
now and I will say a send it for a book three, which is this one, it was Twilight and then I will

06:56.350 --> 06:57.520
send it like that.

06:57.970 --> 07:03.730
You can see what I did is I've changed the third record with a new title.

07:04.060 --> 07:07.840
So coming back here, I will do get for all the books.

07:07.840 --> 07:13.990
So we'll remove that ID and you can see this is my third.

07:14.810 --> 07:20.900
So put will update the records and you can update it more more than one field.

07:20.900 --> 07:24.710
At the moment we only changing the title, but you can pass any.

07:25.630 --> 07:34.240
Uh, like, let's say price, I will do price here and then we can decide it to 45 price.

07:34.240 --> 07:41.290
And also I need to do three slash and using method put so selling this.

07:42.250 --> 07:48.390
You can see this is our price and this is our title that we pass here.

07:48.400 --> 07:50.590
So I will come back to get.

07:52.290 --> 07:52.770
Books.

07:53.050 --> 07:56.500
Sand and I can see the new record is there.

07:56.520 --> 07:59.430
Well, there's an old record, but with new data.

08:01.000 --> 08:06.210
So we cover already four methods, which is get all, which is the books.

08:06.220 --> 08:16.900
Then you can get a certain record like that with ID and then you can post create new record and you

08:16.900 --> 08:18.580
can put update new record.

08:18.580 --> 08:21.640
Also very important one is the delete one.

08:21.640 --> 08:29.080
So if you would like to remove the one we have created with the ID of three, you just use the delete

08:29.080 --> 08:30.310
method on it.

08:30.310 --> 08:37.300
So we have books slash three and then if I will send it, there is nothing back because actually that

08:37.330 --> 08:42.070
Twilight saga we've created before has been removed to check it.

08:42.070 --> 08:48.310
If that is the case, I can go get and try to list all the books now.

08:49.840 --> 08:50.560
Send it.

08:50.560 --> 08:54.640
And you can see we are having two books in our system.

08:54.640 --> 08:58.620
So the third one has been removed with the delete method.

08:58.630 --> 08:59.740
So that's it.

08:59.740 --> 09:04.210
That's the main method we have on the Http.

09:04.600 --> 09:08.050
Repeating that again, we have five main methods.

09:08.050 --> 09:14.140
So we have get on the books which will give us the whole set of the books.

09:14.140 --> 09:16.630
Then we have get on the specific book.

09:16.660 --> 09:18.850
It will bring us only one record.

09:19.150 --> 09:23.230
Then we have post for creating new record.

09:23.230 --> 09:29.290
Put for updating the current record and delete for removing.

09:29.290 --> 09:35.350
We have others that are not that really popular to use, so I'm not going to talk about them, but you

09:35.350 --> 09:38.800
can read about it and if you would like to use it, you can use it.

09:38.800 --> 09:45.370
But anyway, that's the main five and that and we will use them in our tutorial.
