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
Requires
- php: ^8.2
- guzzlehttp/guzzle: ^7.0
- illuminate/cache: ^12.0
- illuminate/support: ^12.0
Requires (Dev)
- fakerphp/faker: ^1.23
- laravel/pail: ^1.2.2
- laravel/pint: ^1.13
- laravel/sail: ^1.41
- mockery/mockery: ^1.6
- nunomaduro/collision: ^8.6
- phpunit/phpunit: ^11.5.3
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
- Create a new Laravel project:
composer create-project laravel/laravel [project-name]
- Install the package via Composer:
composer require mariale098/quotes
- Publish the configuration file:
php artisan vendor:publish --provider="Mariale098\Quotes\QuotesServiceProvider" --tag="config"
- Publish the assets:
php artisan vendor:publish --provider="Mariale098\Quotes\QuotesServiceProvider" --tag="assets"
- Publish the quotes-styles:
php artisan vendor:publish --provider="Mariale098\Quotes\QuotesServiceProvider" --tag="quotes-styles" --force
- Configure your Laravel project's
.envfile 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 APIGET /api/quotes- Retrieves a paginated list of quotes (supportslimitandskipparameters)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:
- Update your
welcome.blade.phpview 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>
- 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");
- 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(), ], });
- Install Vue.js dependencies and build the assets:
npm install @vitejs/plugin-vue vue npm run build
- 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)