In this section I'm going to introduce you to API views the Django rest
framework offers a couple of helper classes we can use to create our API
endpoints the API view and the view set both classes are slightly different and
offer their own benefits in this presentation I'm going to talk you
through the API view the API view is the most basic type of view we can use to
build our API it enables us to describe the logic which makes our API endpoint
so what is the API view?
An API view allows us to define functions that match
the standard HTTP methods HTTP GET to get one or more items HTTP POST
to create an item HTTP put to update an item HTTP patch to partially update an
item and finally HTTP delete to delete an item
By allowing us to customize the
function for each HTTP method on our API URL API views give us the most control
over our application logic
this is perfect in cases where you need to do
something a little bit different from simply updating objects in the database
such as calling other apis or working with local files
So when should you use
API views?
A lot of the time it will depend on personal preference as you
learn more about the Django rest framework here are some examples of when
it might be better to use API views
whenever you need full control over your
application logic such as when you're running a very complicated algorithm or
updating multiple data sources in one api call
or when you're processing files
and rendering asynchronous response maybe you're validating a file and
returning the result in the same call
another time you might use it is when
you are calling other external apis or services in the same request and finally
you might want to use api views when you need access to local files or data so
that's a basic overview of the API view don't worry if you don't fully
understand it at this point sometimes you need to see it in action for it to
make sense
in the following lessons in this section I'm going to walk you
through creating a very basic API view step by step