By now, you should know how to create function-based views. Function-based views are just the regular functions inside your views file. In this video, you'll learn how to create class-based views and leverage the benefits of APA views in DRF. Function-based and class-based views each come with their own advantage. Function-based views are easy to implement, offer better readability, it's easier to use decorators with them, and you can quickly write a one-off solution using function-based views. With class-based views, you don't need to write as much code, there's less code duplication, and you can extend the clusters and add features that anytime. Plus, you can write specific methods for each type of HTTP request. Let's get started so you can observe class-based views in action. Open the views.py file from the same booklet project you worked on before, you'll create your first class-based views in this file. Class-based views help you to keep your code clean and less cluttered, and you can avoid writing extra code by reusing the common functionalities. To create a class-based view in a DRF project, you must extend the APA view class, so let's import it first from the rest framework module. You also need to import the response class. Let's create a class called BookList that extends the APA view class. When adding methods in a class name, you should name them the same as the HTTP verbs. For example, get and post. Now, let's return a simple message from this method. It is time to map this class-based view in the BookList API apps URL.py file. Open the BookLlist API/URLs.py file, remove the old mapping, and add this line to the URL patterns array to map the whole class as a view, you don't need to map each class method separately. Now, you can visit the endpoint /api/books. This endpoint will not accept an HTTP post request because there isn't a post method in this BookList class. Let's add one. The post method also accepts three or four arguments, like the getMethod. Remember, you're using the browsable API view. This means you can taste this post method right from your browser. Visit the books endpoint and scroll to the bottom where you can add request parameters in the Content textbox. For now, just click on the post button and tastes output. Now, come back to the getMethod. What if the APA client wants to list the books by a specific author, how can we exit the query string parameter from the falling request? /api/books?author equals Hemingway. You can exit the query string parameters using the request argument. The author parameter can be accessed using request.GET.get, and then author Insight question mark, and a set of parenthesis. Let's change the getMethod to display the author's name. If the author name is passed to the URL, it shows only that author's book. Otherwise, it'll show all books. Next, visit the URL /api/books?author equals Hemingway and check the result. You can accept the GSM or form URL-encoded data elements in a post method using request.data.get, open and close brackets. Now, visit the book's endpoint in the browser, scroll to the bottom, and in the Content textbox, add this JSON data. This is called a payload. Payload is a common term used for any JSON data or form URL-encoded data that you sent to an API. Now, modify the post method to return the title from the payload. Just like this. Click on the post button and check the result. Now, I'll demonstrate how to accept the primary key in the methods of class-based views. To do that, create a new class called book. This class will manipulate the single book item. This time, add a getMethod with an extra parameter, the primary key, and denote it as PK. Open the BookList API file and map this new book class to the URL patterns array. Now, visit the endpoint /api/books/1, note the ID of the book in the APA result. The put method, however, is a little different. You must add the extra argument pk and you can access the request parameters using (request.data.get) just like the previously created post method. Visit the following URL and send adjacent payload. The URL is local host and then API/books/1. Click the Put button, and note the output. Like the APA view decorator, you can use throttling and authentication policies. You'll learn about this later in this course.