Skip to content

sereitepy/laravel-quote-management

Repository files navigation

Laravel Quote Management API Project

Allows users to fetch random quotes from an external API, save their favorites, and manage them via CRUD operations with proper authentication.

Setup Instructions

I'm using:

  • PHP 8.4.3
  • Laravel Framework 12.2.0
  • Composer 2.8.6
  • MySQL (Port 8889) Ver 8.0.40 for macos12.7 on arm64 (Source distribution)
  • MAMP Pro

Installation Steps

  1. Clone this repository to your local machine:

     git clone https://github.com/sereitepy/laravel-quote-management.git
     cd quote-management
  2. My .env file: according to what my MAMP settings are.

    DB_CONNECTION=mysql
    DB_HOST=127.0.0.1
    DB_PORT=8889
    DB_DATABASE=quote-management
    DB_USERNAME=root
    DB_PASSWORD=
    DB_SOCKET=/Applications/MAMP/tmp/mysql/mysql.sock
    
  3. Run database migrations:

    php artisan migrate
  4. Start the development server:

    php artisan serve

Testing with Postman

Important Notes! Really important!

  • Set Headers Accept: application/json for ALL requests
  • For authenticated endpoints, set Headers Authorization: Bearer {your_token} after logging in
  • The random quotes endpoint may take around 5 seconds to respond as it fetches 10 quotes from an API that fetches 1 quote at a time. 'https://zenquotes.io/api/random'
Screenshot 2025-03-15 at 1 31 06 in the afternoon

API Endpoints

Authentication

Register: POST http://127.0.0.1:8000/api/register

{
  "name": "animalLover",
  "email": "[email protected]",
  "password": "password123"
}
Screenshot 2025-03-15 at 1 32 26 in the afternoon
  • The database should include the user that has been registered. In this image, it should include:
    {
      "user": {
          "name": "animalLover",
          "email": "[email protected]",
          "updated_at": "2025-03-15T04:59:09.000000Z",
          "created_at": "2025-03-15T04:59:09.000000Z",
          "id": 4
      },
      "token": "3|U6vPECcKOb6l4q1lFInB3txz1NWWP2UVDkvVuIQw7c65ff5a"
    }
Screenshot 2025-03-15 at 1 33 18 in the afternoon

Login: POST http://127.0.0.1:8000/api/login

{
  "email": "[email protected]",
  "password": "password123"
}

Important: Save the token returned as it's required for all authenticated requests! Screenshot 2025-03-15 at 1 37 01 in the afternoon


Quotes (Authenticated Routes)

Get Random Quotes: GET http://127.0.0.1:8000/api/quotes/random

  • Note: This request takes around 5 seconds as it fetches 10 quotes
Screenshot 2025-03-15 at 1 38 30 in the afternoon

Save a Quote: POST http://127.0.0.1:8000/api/quotes

{
    "content": "We think too much and feel too little.",
    "author": "Charlie Chaplin"
}
Screenshot 2025-03-15 at 1 40 27 in the afternoon
  • The database should contain the saved quote
Screenshot 2025-03-15 at 1 41 13 in the afternoon

Get Saved Quotes: GET http://127.0.0.1:8000/api/quotes

Screenshot 2025-03-15 at 1 41 59 in the afternoon

Delete a Quote: DELETE http://127.0.0.1:8000/api/quotes/{id}

  • The saved quote id is: 3
Screenshot 2025-03-15 at 1 43 09 in the afternoon
  • Inside the database, the 'Quotes', should be empty.
Screenshot 2025-03-15 at 1 43 35 in the afternoon

Project Structure

  • app/Http/Controllers/ - Contains all the controllers
  • app/Models/ - Database models
  • database/migrations/ - Database migrations
  • routes/api.php - API route definitions

Features

  • User registration and authentication using Laravel Sanctum
  • Integration with ZenQuotes API to fetch random quotes 'https://zenquotes.io/api/random'
  • CRUD operations for managing favorite quotes
  • Form validation and error handling
  • Token-based API authentication

Security

This project implements:

  • Password hashing using Laravel's built-in mechanisms
  • Protected API routes using Sanctum middleware
  • Input validation for all endpoints
  • Protection against common vulnerabilities (CSRF, XSS, SQL Injection)

License

The Laravel framework is open-sourced software licensed under the MIT license.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages