WEBVTT
Kind: captions
Language: en

00:00:00.030 --> 00:00:05.549
Let's talk about view sets at the
beginning of the last section I

00:00:05.549 --> 00:00:10.920
mentioned that the Django rest framework
offers two classes that help us write

00:00:10.920 --> 00:00:17.620
the logic for our API the API view and
the view set

00:00:17.620 --> 00:00:18.900
In the last section I

00:00:18.900 --> 00:00:23.519
introduced you to the API view and in
this section I'm going to teach you how

00:00:23.519 --> 00:00:25.900
to use the view set.

00:00:25.900 --> 00:00:31.830
So what are view sets? Just like API views, view sets allow

00:00:31.830 --> 00:00:36.960
us to write the logic for our endpoints
however instead of defining functions

00:00:36.960 --> 00:00:44.250
which map to HTTP methods view sets
accept functions that map to common API

00:00:44.250 --> 00:00:50.700
object actions such as list for getting
a list of objects

00:00:50.700 --> 00:00:53.250
Create for creating

00:00:53.250 --> 00:01:00.570
new objects retrieve for getting a
specific object update for updating an

00:01:00.570 --> 00:01:06.630
object partial update for updating part
of an object and finally destroy for

00:01:06.630 --> 00:01:09.460
deleting an object

00:01:09.460 --> 00:01:12.180
Additionally view sets can take care a

00:01:12.180 --> 00:01:17.850
lot of the common logic for us they're
perfect for writing apis that perform

00:01:17.850 --> 00:01:22.890
standard database operations and they're
the fastest way to make an api which

00:01:22.890 --> 00:01:26.640
interfaces with a database back-end

00:01:26.640 --> 00:01:30.150
So when should you use view sets? Well a lot

00:01:30.150 --> 00:01:34.680
of the time this comes down to personal
preference however here are some

00:01:34.680 --> 00:01:40.740
examples of cases when you might want to
prefer a view set over an API view for

00:01:40.740 --> 00:01:46.530
example if you need to write an API that
performs a simple create read update and

00:01:46.530 --> 00:01:51.340
delete operation on an existing database
model

00:01:51.340 --> 00:01:54.270
or you need a quick and simple API

00:01:54.270 --> 00:02:00.630
to manage predefined objects or maybe
you need a very basic custom logic

00:02:00.630 --> 00:02:04.890
additional to the view set features
already provided by the Django rest

00:02:04.890 --> 00:02:06.080
framework

00:02:06.080 --> 00:02:09.869
we'll learn more about that
one in a bit finally you might want to

00:02:09.869 --> 00:02:13.160
use a view set if your API is working
with

00:02:13.160 --> 00:02:20.780
standard database structure that's a
basic overview of the view set don't

00:02:20.780 --> 00:02:22.820
worry if you don't fully understand it
at this point

00:02:22.820 --> 00:02:27.050
sometimes you need to see an action for
it to make sense so in the following

00:02:27.050 --> 00:02:32.150
lessons in this section I'm going to
walk you through creating a very basic

00:02:32.150 --> 00:02:36.340
view set step by step

