π» Django REST Framework π»
Posted on Sep 13th, 2022
ποΈ Todayβs Topics
Today we dive into Django REST Framework. π€Ώ
π― Project: Choose Your Own Adventure πͺ π«
Choose one of the following options.
The application must be deployed to Heroku, whichever option you choose. π
πͺ OPTION ONE: Add an API to Habit Tracker
Add a new app to your existing Habit Tracker project and call it api
. Your app should provide CRUD endpoints that return JSON responses.
By Friday afternoon, you should be able to do almost all of the following via the API β that is, by making requests using Insomnia.
- get a list habits
- create a new habit
- get data about a specific habit that includes its associated daily records, if any
- create a record for a specific habit for today (stretch: create a record for any date)
By Monday, you should be able to complete all necessary CRUD tasks through the API:
- list habits
- create a new habit
- update a habit
- delete a habit
- get data about a specific habit that includes its associated daily records, if any
- create a record for a habit for today (stretch: create a record for any date)
- update a record for a habit
- delete a record from a habit
Write up a list of endpoints you think you will need before you start doing this. Donβt make endpoints you donβt need.
You should develop and test your endpoints using Insomnia. (You can also use the browsable API that DRF gives you in the browser, but you should be comfortable using Insomnia.)
π« OPTION TWO: Django Library API
Link to assignment invitation.
Create a new API-only application that lets users keep track of books they are reading, want to read, or have read, and take private or public notes on books. More details about project requirements are included in the assignment README.
You should not make forms or templates for this app, but you will need models, urls, views, and serializers. You should use class-based views and return JSON responses.
π Read | πΊ Watch | π§ Listen
- π REST Resource Naming Guide This resource will be very helpful in thinking about how to structure your urls.
- π§ DjangoChat Podcast: DRF
- π DRF class-based views This talks about
APIView
. - π Class-based vs. function-based views This is about Django views in general, not specific to DRF.
- π« πΊ What You Should Know About DRF, Lacey Williams Henschel, PyCascades 2021
π Resources
- Django REST Framework Documentation
- π Classy Django REST Framework This is exceptionally useful for working with classes in DRF.
- Python
pprint
module docs - Django docs: Introduction to class-based views
Blog articles that go with Lacey Williams Henschelβs talk
- What You Should Know About DRF, Part 1: ModelViewSet attributes and methods
- What You Should Know About DRF, Part 2: Customizing built-in methods
- What You Should Know About DRF, Part 3: Adding custom endpoints