IsuruFerna / BE_Django-FoodRecipes

0 stars 0 forks source link

Django DRF Recipes API Documentation

This is a Python Django backend project for a food recipe app. Users can register and manage recipes and categories. Below is a detailed explanation of the API functionality, along with instructions on how to set up and use the application.


Table of Contents

  1. Introduction
  2. How to Use the App
  3. API Overview
  4. Authentication
  5. Project Features
  6. Technologies Used
  7. Development Setup
  8. API Documentation

Introduction

This project is a Python Django backend for a food recipe app. Users can register, add, modify, and delete recipes and categories. GET requests do not require authentication, allowing anyone to access them without registering. However, actions such as adding, modifying, or deleting posts or categories require user authentication. Only the users who created recipes or categories can modify or delete them.

To make the API endpoints easy to understand, I used Swagger and Redoc to provide comprehensive API documentation.

Throughout this project, I learned to use the Django Rest Framework and GitHub Actions to handle the entire development process through continuous integration (CI). I also employed Docker to containerize the project, using Docker volumes to store persistent data, ensuring data retention even if the containers are removed.


How to Use the App

Starting the Application

To build and run the application, use the following Docker commands:

Database Migration

After building the containers, migrate the database using the following commands:

API Overview

The API is structured into two main sections: Recipes and User. Below are the available endpoints and their descriptions.

Recipes Endpoints

Method Endpoint Description
GET /recipes/ Retrieve a list of all recipes.
GET /recipes/categories/ Retrieve a list of all categories.
POST /recipes/category/ Create a new category (requires authentication).
GET /recipes/category/{category_id}/ Retrieve a specific category by ID.
PATCH /recipes/category/{category_id}/ Update a category by ID (requires authentication).
DELETE /recipes/category/{category_id}/ Delete a category by ID (requires authentication).
POST /recipes/meal/ Create a new meal (requires authentication).
GET /recipes/meal/{meal_id}/ Retrieve a specific meal by ID.
PATCH /recipes/meal/{meal_id}/ Update a meal by ID (requires authentication).
DELETE /recipes/meal/{meal_id}/ Delete a meal by ID (requires authentication).
GET /recipes/random/ Retrieve a random recipe.
GET /recipes/search/ Search for recipes using query parameters.

User Endpoints

Method Endpoint Description
POST /user/api/token/ Obtain a new token for authentication.
POST /user/api/token/refresh/ Refresh the authentication token.
GET /user/me/ Retrieve the authenticated user's details.
PUT /user/me/ Update the authenticated user's details.
POST /user/register/ Register a new user.
GET /user/{user_id}/ Retrieve a specific user's details by ID.

Authentication

Project Features

Technologies Used

Development Setup

To set up the project locally, follow these steps:

  1. Clone the repository:

    
    git clone https://github.com/IsuruFerna/BE_Django-FoodRecipes.git
    cd <repository-directory>
  2. How to Use the App

API Documentation

Method Endpoint Description
GET `` API documentation provided Swagger
GET /api/schema/redoc/ API documentation provided Redoc(well detailed)

Swagger UI

For a comprehensive view of the API endpoints, refer to the Swagger UI documentation. You can access it locally via http://127.0.0.1:8000/.

Swagger UI Screenshot

image

Redoc UI

For a detailed endpoint experience, refer to the Redoc UI documentation. Access it at: http://127.0.0.1:8000/api/schema/redoc

Redoc UI Screenshot

image

Front-end - under development

Repo: https://github.com/IsuruFerna/FE_React-FoodRecipes/tree/development