From 6383c6177afb7375260cf965cd9b23ac735132d9 Mon Sep 17 00:00:00 2001 From: FeliPython Date: Sun, 28 Apr 2024 13:58:46 -0300 Subject: [PATCH] Add new album endpoint in API documentation Expanded the "Building an API - Part II" section in the documentation to include detailed steps for creating an endpoint for the album model. This includes modifications to the 'music.urls.py' file in order to add routing for the newly created AlbumViewSet. --- docs/images/index.md | 24 +++++++++++++++++++++++- first_api/music/urls.py | 3 ++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/docs/images/index.md b/docs/images/index.md index 0ec9999..a6e7b85 100644 --- a/docs/images/index.md +++ b/docs/images/index.md @@ -313,8 +313,30 @@ Congratulations now you have your first api working. - ⏳ Time for rest and informal discussions. ## Building an API - Part II -Ok, so now we are going to create the apis for the other 2 models album and song model. + +Now that you've explored some of the shortcuts provided by DRF, let's delve into creating an endpoint for the album model using a plain Serializer, without relying heavily on shortcuts. + +Let's start by the urls part. We gonna need to add the new route to our `music.urls.py`. Now it should look like this. +```python +from django.urls import path, include +from rest_framework import routers + +from . import views +from .views import ArtistViewSet, AlbumViewSet + +router = routers.DefaultRouter() +router.register(r'artists', ArtistViewSet) +router.register(r'albums', AlbumViewSet) + +urlpatterns = [ + path('', include(router.urls)), + # path('', views.index, name='index'), +] + +``` +1. We added a new import for the AlbumViewSet +2. We added the routes for albums ## Bonus content ### Serializers deep dive diff --git a/first_api/music/urls.py b/first_api/music/urls.py index 1d302d3..19b51ad 100644 --- a/first_api/music/urls.py +++ b/first_api/music/urls.py @@ -2,10 +2,11 @@ from rest_framework import routers from . import views -from .views import ArtistViewSet +from .views import ArtistViewSet, AlbumViewSet router = routers.DefaultRouter() router.register(r'artists', ArtistViewSet) +router.register(r'albums', AlbumViewSet) urlpatterns = [ path('', include(router.urls)),