WEBVTT
Kind: captions
Language: en

00:00:00.030 --> 00:00:06.750
In this section I'm going to introduce
you to API views the Django rest

00:00:06.750 --> 00:00:11.759
framework offers a couple of helper
classes we can use to create our API

00:00:11.759 --> 00:00:20.189
endpoints the API view and the view set
both classes are slightly different and

00:00:20.189 --> 00:00:24.930
offer their own benefits in this
presentation I'm going to talk you

00:00:24.930 --> 00:00:31.650
through the API view the API view is the
most basic type of view we can use to

00:00:31.650 --> 00:00:38.510
build our API it enables us to describe
the logic which makes our API endpoint

00:00:38.510 --> 00:00:41.700
so what is the API view?

00:00:41.700 --> 00:00:45.840
An API view
allows us to define functions that match

00:00:45.840 --> 00:00:54.750
the standard HTTP methods HTTP GET to
get one or more items HTTP POST

00:00:54.750 --> 00:01:02.969
to create an item HTTP put to update an
item HTTP patch to partially update an

00:01:02.969 --> 00:01:08.240
item and finally HTTP delete to delete
an item

00:01:08.240 --> 00:01:10.350
By allowing us to customize the

00:01:10.350 --> 00:01:17.580
function for each HTTP method on our API
URL API views give us the most control

00:01:17.580 --> 00:01:20.720
over our application logic

00:01:20.720 --> 00:01:23.520
this is
perfect in cases where you need to do

00:01:23.520 --> 00:01:27.799
something a little bit different from
simply updating objects in the database

00:01:27.800 --> 00:01:33.780
such as calling other apis or working
with local files

00:01:33.780 --> 00:01:35.560
So when should you use

00:01:35.560 --> 00:01:37.520
API views?

00:01:37.520 --> 00:01:41.640
A lot of the time it will
depend on personal preference as you

00:01:41.640 --> 00:01:46.170
learn more about the Django rest
framework here are some examples of when

00:01:46.170 --> 00:01:49.940
it might be better to use API views

00:01:49.940 --> 00:01:52.200
whenever you need full control over your

00:01:52.200 --> 00:01:57.149
application logic such as when you're
running a very complicated algorithm or

00:01:57.149 --> 00:02:02.100
updating multiple data sources in one api call

00:02:02.100 --> 00:02:04.380
or when you're processing files

00:02:04.380 --> 00:02:09.390
and rendering asynchronous response
maybe you're validating a file and

00:02:09.390 --> 00:02:12.760
returning the result in the same call

00:02:12.760 --> 00:02:15.120
another time you might use it is when

00:02:15.120 --> 00:02:22.080
you are calling other external apis or
services in the same request and finally

00:02:22.080 --> 00:02:28.920
you might want to use api views when you
need access to local files or data so

00:02:28.920 --> 00:02:33.480
that's a basic overview of the API view
don't worry if you don't fully

00:02:33.480 --> 00:02:37.710
understand it at this point sometimes
you need to see it in action for it to

00:02:37.710 --> 00:02:39.340
make sense

00:02:39.340 --> 00:02:42.510
in the following lessons in
this section I'm going to walk you

00:02:42.510 --> 00:02:48.830
through creating a very basic API view
step by step

