REST APIs with Django REST Framework
Turn the Akwaaba Blog into a JSON API with Django REST Framework: serializers, viewsets, tokens, permissions, pagination, tests and CORS.
- 1 students
- 99 lessons
- 7 h 43 min
Created by Ayim Nelson
What you will learn
- Explain REST, HTTP methods, status codes and JSON
- Turn models into JSON and check incoming data with serializers
- Build API endpoints with function views, generic views and viewsets
- Protect an API with token authentication and custom permissions
- Add pagination, search, ordering, throttling and URL versioning
- Write API tests with APITestCase and APIClient
- Call the API from JavaScript and set up CORS for a front end
About this course
A website shows pages to people. An API serves data to other programs: phone apps, JavaScript front ends and other servers. In this course you take the Akwaaba Blog you built in The Ultimate Django Course and give it a JSON API with Django REST Framework, one short lesson at a time. Every request and response you see was produced by running the real code on Django 6.1 and DRF 3.18.
For: anyone who finished The Ultimate Django Course, or who already knows Django basics: models, views, URLs and the admin. You'll work on your own computer, with Python 3.12 or newer.
By the end: you'll have a versioned, tested and secure JSON API for the blog, where anyone can read published posts, signed-in writers create and edit their own posts with a token, and a JavaScript front end can fetch it all.
Course content
11 sections · 99 lessons
APIs, REST and JSON9 lessons
- What an API isPreviewReading · 3 min
- From blog pages to a JSON APIPreviewReading · 3 min
- Requests and responsesPreviewReading · 4 min
- HTTP methodsReading · 4 min
- Status codesReading · 4 min
- JSON and PythonReading · 4 min
- What makes an API RESTfulReading · 4 min
- Designing the blog's endpointsReading · 4 min
- Turn a post into JSONExercise · 12 min
Setting up Django REST Framework8 lessons
- What Django REST Framework gives youReading · 3 min
- Installing DRFReading · 3 min
- Adding DRF and an api appReading · 4 min
- Your first API viewReading · 4 min
- Giving the API its URLsReading · 4 min
- Seeing it in the browserReading · 4 min
- Methods a view doesn't accept: 405Reading · 3 min
- Build a JSON responseExercise · 10 min
Serializers13 lessons
- What a serializer doesReading · 3 min
- The blog's sample dataReading · 3 min
- A first SerializerReading · 4 min
- Many objects, then JSONReading · 4 min
- ModelSerializerReading · 4 min
- Checking incoming dataReading · 4 min
- Read-only fieldsReading · 4 min
- Validation errorsReading · 4 min
- Validating one fieldReading · 4 min
- Validating the whole objectReading · 4 min
- Creating with save()Reading · 4 min
- Updating and partial updatesReading · 4 min
- Validate a post payloadExercise · 12 min
Nested data and relations9 lessons
- Relations show up as idsReading · 3 min
- Names instead of idsReading · 4 min
- Nesting a serializerReading · 4 min
- Writable tags with SlugRelatedFieldReading · 4 min
- Counting commentsReading · 4 min
- The finished PostSerializerReading · 4 min
- Methods as fieldsReading · 4 min
- Avoiding extra queriesReading · 4 min
- Build a nested postExercise · 12 min
API views10 lessons
- Function views with @api_viewReading · 4 min
- Listing postsReading · 3 min
- Creating a post with POSTReading · 4 min
- Sending bad data: 400Reading · 3 min
- A detail view for one postReading · 4 min
- Changing and deleting a postReading · 4 min
- Class-based APIViewReading · 4 min
- Generic viewsReading · 4 min
- Hooks: get_queryset and perform_createReading · 5 min
- Route methods to handlersExercise · 12 min
ViewSets and routers9 lessons
- What a ViewSet isReading · 3 min
- A ModelViewSet for postsReading · 4 min
- Routers write the URLsReading · 4 min
- The API rootReading · 3 min
- A read-only ViewSet for tagsReading · 3 min
- Extra actions with @actionReading · 4 min
- Versioning in the URLReading · 4 min
- Which kind of view to useReading · 3 min
- Build URLs like a routerExercise · 12 min
Authentication and permissions11 lessons
- Authentication and permissionsReading · 3 min
- Session authenticationReading · 4 min
- Setting default permissionsReading · 4 min
- 401 or 403?Reading · 4 min
- Writing IsAuthorOrReadOnlyReading · 4 min
- Object permissions in actionReading · 4 min
- Token authenticationReading · 4 min
- Getting a tokenReading · 4 min
- Sending the tokenReading · 4 min
- Tokens, JWT and logging outReading · 4 min
- Check permissionsExercise · 12 min
Pagination, filtering and limits10 lessons
- Why paginateReading · 3 min
- Turning on paginationReading · 4 min
- Moving between pagesReading · 4 min
- Other pagination stylesReading · 3 min
- Filtering by tagReading · 4 min
- Search with SearchFilterReading · 4 min
- Ordering with OrderingFilterReading · 3 min
- Throttling basicsReading · 4 min
- Too many requests: 429Reading · 3 min
- Paginate with next and previous linksExercise · 14 min
Testing your API8 lessons
- APITestCase and APIClientReading · 3 min
- Test data in setUpReading · 4 min
- Testing a listReading · 4 min
- Logging in inside testsReading · 4 min
- Testing permissionsReading · 4 min
- Testing tokensReading · 4 min
- Running the testsReading · 3 min
- Test a permission ruleExercise · 12 min
Documentation, JavaScript and going live9 lessons
- Documenting the APIReading · 4 min
- Fetching posts with JavaScriptReading · 4 min
- Sending a post with fetchReading · 4 min
- Handling errors in JavaScriptReading · 4 min
- What CORS isReading · 4 min
- Allowing your front end with django-cors-headersReading · 5 min
- Settings for going liveReading · 4 min
- Deploying the APIReading · 4 min
- Read every pageExercise · 14 min
Wrapping up3 lessons
- What you builtReading · 3 min
- Where to go nextReading · 3 min
- Final quizQuiz · 10 min
Reviews
No reviews yet.
Comments
Log in to join the conversation.
Loading comments...