diff --git a/docs/Guides/Django REST Framework/1 - Setup.md b/docs/Guides/Django REST Framework/1 - Setup.md index 8bdab08..b9f3b4d 100644 --- a/docs/Guides/Django REST Framework/1 - Setup.md +++ b/docs/Guides/Django REST Framework/1 - Setup.md @@ -58,3 +58,5 @@ This guide does not cover the proper usage of Git and so you may need to look up You can proceed with the typical installation using defaults (no need to change anything), just click Next/Install. With that out of the way, you can proceed to setting up your Django REST Framework project. + +Up Next: [2 - Initialize your First Project](2%20-%20Initialize%20your%20First%20Project.md) \ No newline at end of file diff --git a/docs/Guides/Django REST Framework/2 - Initialize your First Project.md b/docs/Guides/Django REST Framework/2 - Initialize your First Project.md index d1c92f9..7ce0979 100644 --- a/docs/Guides/Django REST Framework/2 - Initialize your First Project.md +++ b/docs/Guides/Django REST Framework/2 - Initialize your First Project.md @@ -89,4 +89,6 @@ Once that's done, run the command `python manage.py runserver 0.0.0.0:8000` to s Your Django project will now be visible on the URL **[https://localhost:8000](https://localhost:8000)** -![377f5134b0525b830116a64d7699368f_MD5](_resources/2%20-%20Initialize%20your%20First%20Project/377f5134b0525b830116a64d7699368f_MD5.jpg) \ No newline at end of file +![377f5134b0525b830116a64d7699368f_MD5](_resources/2%20-%20Initialize%20your%20First%20Project/377f5134b0525b830116a64d7699368f_MD5.jpg) + +Up Next: [3 - Project Structure](3%20-%20Project%20Structure.md) \ No newline at end of file diff --git a/docs/Guides/Django REST Framework/3 - Project Structure.md b/docs/Guides/Django REST Framework/3 - Project Structure.md index f5a6a98..f234ed8 100644 --- a/docs/Guides/Django REST Framework/3 - Project Structure.md +++ b/docs/Guides/Django REST Framework/3 - Project Structure.md @@ -78,4 +78,6 @@ Add **rest_framework** to **INSTALLED_APPS** ![c327ae10edcfd245d0ad4cfe787bf9ae_MD5](_resources/3%20-%20Project%20Structure/c327ae10edcfd245d0ad4cfe787bf9ae_MD5.jpg) -The next section will then tackle building a REST API with DRF \ No newline at end of file +The next section will then tackle building a REST API with DRF. + +Up Next: [4 - REST Framework Setup](4%20-%20REST%20Framework%20Setup.md) \ No newline at end of file diff --git a/docs/Guides/Django REST Framework/4 - REST Framework Setup.md b/docs/Guides/Django REST Framework/4 - REST Framework Setup.md index b12abc4..ac41414 100644 --- a/docs/Guides/Django REST Framework/4 - REST Framework Setup.md +++ b/docs/Guides/Django REST Framework/4 - REST Framework Setup.md @@ -52,4 +52,6 @@ Your setup should then look like this There is no need to include the **api** app in your **INSTALLED\_APPS (config/settings.py)** -The next section will handle users and authentication \ No newline at end of file +The next section will handle users and authentication + +Up Next: [5 - User Setup and Migrations](5%20-%20User%20Setup%20and%20Migrations.md) \ No newline at end of file diff --git a/docs/Guides/Django REST Framework/5 - User Setup and Migrations.md b/docs/Guides/Django REST Framework/5 - User Setup and Migrations.md index 64c9138..f0e5e1c 100644 --- a/docs/Guides/Django REST Framework/5 - User Setup and Migrations.md +++ b/docs/Guides/Django REST Framework/5 - User Setup and Migrations.md @@ -229,4 +229,6 @@ With that out of the way, running your Django project (`python manage.py runserv It's always important to apply your migrations before running your app, otherwise you might run into issues. -In the next section, you will be creating your first (superuser) account to access the Django admin panel. \ No newline at end of file +In the next section, you will be creating your first (superuser) account to access the Django admin panel. + +Up Next: [6 - Django Admin](6%20-%20Django%20Admin.md) \ No newline at end of file diff --git a/docs/Guides/Django REST Framework/6 - Django Admin.md b/docs/Guides/Django REST Framework/6 - Django Admin.md index 5de5b50..2c3e7ae 100644 --- a/docs/Guides/Django REST Framework/6 - Django Admin.md +++ b/docs/Guides/Django REST Framework/6 - Django Admin.md @@ -20,4 +20,6 @@ To create a superuser or administrator account. Open a terminal inside your Djan Be sure to enter a secure password! Django has password validators built-in and may warn you. -![image.png](_resources/6%20-%20Django%20Admin/de9dd7f7b5589adcd14eb7a5358eeaa0_MD5.jpg) \ No newline at end of file +![image.png](_resources/6%20-%20Django%20Admin/de9dd7f7b5589adcd14eb7a5358eeaa0_MD5.jpg) + +Up next: [7 - Writing API Endpoints](7%20-%20Writing%20API%20Endpoints.md) diff --git a/docs/Guides/Django REST Framework/7 - Writing API Endpoints.md b/docs/Guides/Django REST Framework/7 - Writing API Endpoints.md index 13c7d30..038e48e 100644 --- a/docs/Guides/Django REST Framework/7 - Writing API Endpoints.md +++ b/docs/Guides/Django REST Framework/7 - Writing API Endpoints.md @@ -37,6 +37,7 @@ Serializers define the model used using the class **Meta**. Using a DRF serializ The serializer above only returns 4 fields (id, username, email, full\_name). Any other fields are omitted such as age, birthday, and so on. +Serializers can be found in the `serializers.py` file of a Django REST Framework app. #### Serializer - Validation In addition to manipulating your model before JSON serialization, DRF serializers allow you to validate fields to ensure proper values are provided. ![image.png](_resources/7%20-%20Writing%20API%20Endpoints/972f5b24877092dabefa35683e9d8a37_MD5.jpg) @@ -81,4 +82,31 @@ Knowing where you should place your validation functions is something you will e If you're just starting off, this isn't something you should be too worried about. Just knowing that the serializer parses to JSON is plenty enough to get started with building CRUD apps. ### Views -Work in progress! \ No newline at end of file +If serializers convert the underlying model to JSON, then views return the web response. They are situated in the `views.py` file of a Django REST Framework app. +![](_resources/7%20-%20Writing%20API%20Endpoints/9bb3d5c0c6da24a9d80d81d1e5b4a716_MD5.jpeg) +Views take in HTTP requests passed in from the actual URL. You can specify a `queryset` to define what objects to return and specify a serializer which will be used to structure the returned data. + +Much like with DRF serializers, you can customize them what's returned. This can be to check whether the user owns what he/she's modifying and then forbidding access, or something else entirely depending on your use case. +![](_resources/7%20-%20Writing%20API%20Endpoints/695f930d4993ff8d8f2ccf806bd9ca9f_MD5.jpeg) +If you're using Memcached or Redis, you'll most likely have it integrated here, similar to the example above. Caching is something you won't have to worry about right now and will be tackled in later sections. + +### Note! +The concept of serializers only exist within Django REST Framework and APIs. If you're using only Django as a full stack framework, without any API endpoints and without Django REST Framework, you likely won't run into them at all. + +Many of you will also notice that there's two ways to go about setting up restrictions, one within views and another in the serializer itself. This will be discussed further in the next section. +### URLs +URLs are the most self-explanatory part of this section. They define the URL that should be used for your API endpoint. They can be found in the `urls.py` file of your Django REST Framework app. +![](_resources/7%20-%20Writing%20API%20Endpoints/9c1af7c5c436fec290cc1dbda9c9ac5c_MD5.jpeg) + +URLs must be included in your `urlpatterns`, otherwise, they will not be registered in your API. + +You can build complex URLs by nesting paths, similar to what we've done with [4 - REST Framework Setup](4%20-%20REST%20Framework%20Setup.md) (e.g. `https://localhost:8000/api/v1/notifications/) +![](_resources/7%20-%20Writing%20API%20Endpoints/6a3d52433be9340109bf93795854e3b8_MD5.jpeg) + +When using viewset templates, you will need to specify a router to handle generation of all the `GET`, `POST`, and `DELETE` actions among other things since viewsets are effectively templates. + +If on the other hand, you're using [generic views ](https://www.django-rest-framework.org/api-guide/generic-views/), you can simply call them directly inside your `urlpatterns` + +This will be discussed in further detail in [9 - Viewsets vs API Views (Work in progress)](9%20-%20Viewsets%20vs%20API%20Views%20(Work%20in%20progress).md) + +Up next: [8 - Role-Based Access Control (RBAC) (Work in progress)](8%20-%20Role-Based%20Access%20Control%20(RBAC)%20(Work%20in%20progress).md) \ No newline at end of file diff --git a/docs/Guides/Django REST Framework/8 - Role-Based Access Control (RBAC) (Work in progress).md b/docs/Guides/Django REST Framework/8 - Role-Based Access Control (RBAC) (Work in progress).md new file mode 100644 index 0000000..55109d3 --- /dev/null +++ b/docs/Guides/Django REST Framework/8 - Role-Based Access Control (RBAC) (Work in progress).md @@ -0,0 +1,9 @@ + +(Work in progress) +### Role-Based Access Control (RBAC) +There will be instances where you will need to restrict what is returned to the user. +- A student may want to see only the subjects they're currently enrolled in. +- An author would not want to edit a book they don't own +- A bank clerk shouldn't be able to delete bank transactions + +These restrictions and rules all fall under the concept of Role-Based Access Control or RBAC. Whether you're using... \ No newline at end of file diff --git a/docs/Guides/Django REST Framework/9 - Viewsets vs API Views (Work in progress).md b/docs/Guides/Django REST Framework/9 - Viewsets vs API Views (Work in progress).md new file mode 100644 index 0000000..8be4c3e --- /dev/null +++ b/docs/Guides/Django REST Framework/9 - Viewsets vs API Views (Work in progress).md @@ -0,0 +1 @@ +(Work in progress) \ No newline at end of file diff --git a/docs/Guides/Django REST Framework/Django REST Framework.md b/docs/Guides/Django REST Framework/Django REST Framework.md index 81e6148..d98a358 100644 --- a/docs/Guides/Django REST Framework/Django REST Framework.md +++ b/docs/Guides/Django REST Framework/Django REST Framework.md @@ -9,4 +9,6 @@ Django can be used as-is to develop full stack web apps which include your front You will be using Django alongside Django REST Framework to instead build a backend API, which will only serve data from your database, and not serve as a frontend framework. This guide will focus on data, so no fancy frontend design stuff! -This guide has concepts that are similar to the official guide for Django linked [here](https://docs.djangoproject.com/en/5.1/intro/tutorial01/). Check it out as well! \ No newline at end of file +This guide has concepts that are similar to the official guide for Django linked [here](https://docs.djangoproject.com/en/5.1/intro/tutorial01/). Check it out as well! + +Up Next: [1 - Setup](1%20-%20Setup.md) \ No newline at end of file diff --git a/docs/Guides/Django REST Framework/_resources/7 - Writing API Endpoints/695f930d4993ff8d8f2ccf806bd9ca9f_MD5.jpeg b/docs/Guides/Django REST Framework/_resources/7 - Writing API Endpoints/695f930d4993ff8d8f2ccf806bd9ca9f_MD5.jpeg new file mode 100644 index 0000000..c69b201 Binary files /dev/null and b/docs/Guides/Django REST Framework/_resources/7 - Writing API Endpoints/695f930d4993ff8d8f2ccf806bd9ca9f_MD5.jpeg differ diff --git a/docs/Guides/Django REST Framework/_resources/7 - Writing API Endpoints/6a3d52433be9340109bf93795854e3b8_MD5.jpeg b/docs/Guides/Django REST Framework/_resources/7 - Writing API Endpoints/6a3d52433be9340109bf93795854e3b8_MD5.jpeg new file mode 100644 index 0000000..7ae28a3 Binary files /dev/null and b/docs/Guides/Django REST Framework/_resources/7 - Writing API Endpoints/6a3d52433be9340109bf93795854e3b8_MD5.jpeg differ diff --git a/docs/Guides/Django REST Framework/_resources/7 - Writing API Endpoints/9bb3d5c0c6da24a9d80d81d1e5b4a716_MD5.jpeg b/docs/Guides/Django REST Framework/_resources/7 - Writing API Endpoints/9bb3d5c0c6da24a9d80d81d1e5b4a716_MD5.jpeg new file mode 100644 index 0000000..6bb9322 Binary files /dev/null and b/docs/Guides/Django REST Framework/_resources/7 - Writing API Endpoints/9bb3d5c0c6da24a9d80d81d1e5b4a716_MD5.jpeg differ diff --git a/docs/Guides/Django REST Framework/_resources/7 - Writing API Endpoints/9c1af7c5c436fec290cc1dbda9c9ac5c_MD5.jpeg b/docs/Guides/Django REST Framework/_resources/7 - Writing API Endpoints/9c1af7c5c436fec290cc1dbda9c9ac5c_MD5.jpeg new file mode 100644 index 0000000..4e677f1 Binary files /dev/null and b/docs/Guides/Django REST Framework/_resources/7 - Writing API Endpoints/9c1af7c5c436fec290cc1dbda9c9ac5c_MD5.jpeg differ