Here's a README file that includes instructions on how to set up the Laravel project using Laravel Sail and Docker, as well as use cases for each API endpoint:
This Laravel project provides a simple API to fetch random Kanye West quotes. It uses Laravel Sail and Docker for easy development and deployment.
Follow these steps to set up and run the project on your local environment:
- Docker installed on your machine.
-
Clone the repository to your local machine:
git clone https://github.com/designbyjr/kanye.git
-
Navigate to the project directory:
cd kanye-west-quotes-api
-
Copy the
.env.example
file to create a new.env
file:cp .env.example .env
-
Generate Key in
.env
file:php artisan key:generate
-
Set your API token in the
.env
file:API_TOKEN=your-api-token
Replace
your-api-token
with your desired API token. -
Start the Laravel Sail environment using Docker:
./vendor/bin/sail up -d
-
Access the application at http://localhost.
- URL:
/api/quote
- Method:
GET
- Description: Fetches a random Kanye West quote.
- Use Case: Use this endpoint to display a random Kanye West quote on your website or application.
- URL:
/api/quote/refresh
- Method:
GET
- Description: Clears the cache and retrieves a new random Kanye West quote.
- Use Case: Use this endpoint when you want to get a fresh random quote without relying on the cached quote.
-
Get a random Kanye West quote:
curl http://localhost/api/quote
-
Refresh the quote:
curl http://localhost/api/quote/refresh
<?php
require 'vendor/autoload.php';
use GuzzleHttp\Client;
$client = new Client();
// Get a random Kanye West quote
$response = $client->get('http://localhost/api/quote');
$data = json_decode($response->getBody(), true);
$quote = $data['quote'];
echo "Random Quote: $quote\n";
// Refresh the quote
$response = $client->get('http://localhost/api/quote/refresh');
$data = json_decode($response->getBody(), true);
$quote = $data['quote'];
echo "Refreshed Quote: $quote\n";
You can run the feature and unit tests using the following command:
./vendor/bin/sail test
To deploy this application to a production server, follow the Laravel deployment guidelines and make sure to configure your web server (e.g., Nginx or Apache) to serve the Laravel application.
This project is licensed under the MIT License - see the LICENSE file for details.
- Kanye West for the endless wisdom.
That's it! You now have a working Laravel API that fetches random Kanye West quotes. Feel free to customize and extend it as needed for your project.