Skip to content

VitorVieira20/Recipes-API

Repository files navigation

🍽️ Recipe API

A simple RESTful API built with Laravel for managing recipes and categories. It supports searching, category filtering, and JWT-based authentication for protected actions.


📦 Features

  • 🔐 JWT Authentication
  • 📄 CRUD for Recipes and Categories
  • 🔎 Search recipes by name, category, or ingredients
  • 🗂️ Filter recipes by category
  • ✅ API Documentation via Swagger

🔗 Base URL

http://your-domain.com/api

🛠️ Installation

git clone https://github.com/VitorVieira20/Recipes-API.git
cd Recipes-API

composer install
cp .env.example .env
php artisan key:generate

# Configure your database (.env)
php artisan migrate
php artisan serve

🔐 Authentication

All POST, PUT and DELETE requests require authentication via JWT.

Send your token in the Authorization header:

Authorization: Bearer YOUR_TOKEN

🔧 Configuration

In your .env file, make sure to define your secret token key used for signing the JWT:

API_SECRET_TOKEN=your_secret_key_here

Ensure your application uses this key for running successfull tests. You can access it in your code with:

$secret = env('API_SECRET_TOKEN');

📚 API Endpoints

📖 Recipes

GET /api/recipes

Returns all recipes.

GET /api/recipes/search?q=term

Search for recipes by name, category, or ingredients.

GET /api/recipes/category/{categoryId}

Get recipes belonging to a specific category.

GET /api/recipes/{id}

Get a specific recipe by ID.

POST /api/recipes 🔒

Create a new recipe.

Request body example:

{
  "name": "Chocolate Cake",
  "image": "https://example-image.com",
  "description": "Some description",
  "ingredients": ["2 eggs", "1 cup flour", "200g chocolate"],
  "instructions": "Mix everything and bake.",
  "category_id": 1,
}

PUT /api/recipes/{id} 🔒

Update a recipe.

Request body example:

{
  "name": "Updated Recipe Name",
  "ingredients": ["New Ingredient 1", "New Ingredient 2"]
}

DELETE /api/recipes/{id} 🔒

Delete a recipe.


📁 Categories

GET /api/categories

List all categories.

POST /api/categories 🔒

Create a new category.

Request body example:

{
  "name": "Desserts"
}

PUT /api/categories/{id} 🔒

Update a category.

DELETE /api/categories/{id} 🔒

Delete a category.


🧪 Running Tests

php artisan test

The tests will automatically adapt based on the DB driver (MySQL or PostgreSQL).


📘 Swagger Documentation

This project uses OpenAPI annotations. You can generate the docs with:

php artisan l5-swagger:generate

Access the documentation at:

http://your-domain.com/api/documentation

⚙️ Tech Stack

  • Laravel
  • PostgreSQL / MySQL
  • JWT Authentication
  • OpenAPI (Swagger) for docs

📬 License

This project is licensed under the MIT license.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages