Momentum logo
Team 12 Classroom

🐻 Views and Serializers in DRF 🐻

Posted on May 26th, 2022

πŸ—“οΈ Today’s Topics

  • Views and viewsets
  • Nesting and customizing serializers
  • Permissions

🎯 Project

Keep on with your API building 😎 πŸ’ͺ! What do you need to know to get it working?

By now you should have a list of endpoints that your API offers, even if they are not all complete yet. A good place for this would be in your README, formatted with Markdown. This list should show the URLs along with the HTTP methods/verbs, and ideally should include an example of the JSON that has to be included in the request body (for any requests that send data in the body) and an example of the JSON response that will be returned, for each endpoint. This list will be helpful for your own testing and it can serve as necessary documentation for your API.

Here is an example of what your documentation might look like for an endpoint to create a book:


Create a new book

request

Requires authentication.

title and author are required fields.

POST api/books

{
   "title": "The Anatomy of Melancholy",
   "author": "Robert Burton",
   "publication_year": 1621
}

response

201 Created

{
  "pk": 6,
  "title": "The Anatomy of Melancholy",
  "author": "Robert Burton",
  "publication_year": 1621,
  "featured": false,
  "reviews": []
}


By today or tomorrow, your app should respond with json to GET requests for all habits/books, for one habit/book, and for one book/habit’s associated objects (daily records for habits; reviews or trackers for books). By tomorrow you should also have at least some of your POSTs working, and can begin working on updates and deletes.

πŸ’ Make sure you test your endpoints in Insomnia to confirm that they are working as intended.

Is your app deployed to Heroku yet? πŸ‘€ πŸš€

πŸ”– Resources

Serializers

Permissions

πŸ‘Ύ Code

Back to home