Skip to content

Commit

Permalink
Add new album endpoint in API documentation
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
lipemorais committed Apr 28, 2024
1 parent f68788d commit 6383c61
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
24 changes: 23 additions & 1 deletion docs/images/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion first_api/music/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down

0 comments on commit 6383c61

Please sign in to comment.