mariale098/quotes

A Laravel package for interacting with the DummyJSON Quotes API

Installs: 2

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

Language:Blade

pkg:composer/mariale098/quotes

v1.0.0 2025-04-29 19:01 UTC

This package is auto-updated.

Last update: 2025-11-29 20:50:04 UTC


README

A Laravel package for interacting with the DummyJSON Quotes API. This package provides a simple way to fetch and display quotes with caching and rate limiting.

Installation

  1. Create a new Laravel project:
composer create-project laravel/laravel [project-name]
  1. Install the package via Composer:
composer require mariale098/quotes
  1. Publish the configuration file:
php artisan vendor:publish --provider="Mariale098\Quotes\QuotesServiceProvider" --tag="config"
  1. Publish the assets:
php artisan vendor:publish --provider="Mariale098\Quotes\QuotesServiceProvider" --tag="assets"
  1. Publish the quotes-styles:
php artisan vendor:publish --provider="Mariale098\Quotes\QuotesServiceProvider" --tag="quotes-styles" --force
  1. Configure your Laravel project's .env file with the following settings:
# Session Configuration
SESSION_DRIVER=file
# This setting stores session data in files, which is required for the quotes package to work properly

# Cache Configuration
CACHE_STORE=file
# This setting enables file-based caching for storing quotes data

# Queue Configuration
QUEUE_CONNECTION=sync
# This setting ensures that quote operations are processed synchronously

These settings are essential for the proper functioning of the quotes package, as they:

  • Enable session management for user interactions
  • Provide caching capabilities for API responses
  • Ensure synchronous processing of quote operations

Usage

API Endpoints

The package provides the following API endpoints:

  • GET /api/quotes/random - Fetches a random quote from the API
  • GET /api/quotes - Retrieves a paginated list of quotes (supports limit and skip parameters)
  • GET /api/quotes/{id} - Gets a specific quote by its ID

Vue Component Integration

The package includes a Vue.js component for displaying quotes. Follow these steps to integrate it into your application:

  1. Update your welcome.blade.php view to include the Vue app container and necessary assets:
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>Laravel Quotes</title>
        @vite(['resources/css/app.css'])
    </head>
    <body>
        <div id="app"></div>
        @vite(['resources/js/app.js'])
    </body>
</html>
  1. Import and mount the component in your resources/js/app.js:
import { createApp } from 'vue';
import QuotesComponent from './components/QuotesComponent.vue';

createApp(QuotesComponent).mount("#app");
  1. Configure Vite by updating your vite.config.js:
import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
import tailwindcss from '@tailwindcss/vite';
import vue from '@vitejs/plugin-vue';

export default defineConfig({
    plugins: [
        laravel({
            input: ['resources/css/app.css', 'resources/js/app.js'],
            refresh: true,
        }),
        tailwindcss(),
        vue(),
    ],
});
  1. Install Vue.js dependencies and build the assets:
npm install @vitejs/plugin-vue vue
npm run build
  1. Start the Laravel development server to test your application:
php artisan serve

Features

  • Random Quote Display: Shows a random quote that changes on page reload
  • Quote Search: Search for quotes by their ID
  • Paginated Quotes List: Browse through quotes with pagination
  • Error Handling: User-friendly error messages
  • Responsive Design: Mobile-friendly interface
  • Caching: Built-in caching for API responses
  • Rate Limiting: Protection against API abuse

Configuration

Customize the package behavior by modifying the config/quotes.php file:

return [
    'cache_ttl' => 3600, // Cache time in seconds (1 hour)
    'rate_limit' => [
        'enabled' => true,
        'max_attempts' => 50, // Maximum API calls per minute
        'decay_minutes' => 1,
    ],
];

Author

Maria Alejandra Garcia Raiola (marialejandra.g98@gmail.com)