This is a simple API to retrieve quotes. At the moment this is limited to Kanye quotes.
- PHP 8.3
- Git
- Composer
git clone [email protected]:advoor/quotes.git
cd quotes
composer install
cp .env.example .env
php artisan key:generate
php artisan migrate
In this example I am using quotes.test
as the domain. You can change this in the .env
file.
To create a user and retrieve a token run the following command:
php artisan app:create-user
Keep the token safe, you will need it to access the API!
If you need to create a new token for an existing user, you can make the following request with your login credentials:
curl --location 'http://quotes.test/api/user' \
--header 'Accept: application/json' \
--form 'email="[email protected]"' \
--form 'password="Password1\!"'
Using the token, you can validate it by making the following request, which will return the user details:
curl --location 'http://quotes.test/api/user' \
--header 'Authorization: Bearer [TOKEN]'
The quotes are retrieved from the Kanye Rest API.
In order to get a quote you can make the following request:
curl --location 'http://quotes.test/api/quotes' \
--header 'Authorization: Bearer [TOKEN]'
By default, the API will return 5 quotes. This can be configured in config/quote.php
.
These quotes are cached for 10 minutes to prevent excessive requests to the Kanye Rest API. If however you want to always retrieve a new quote you can add the ?refresh=true
query parameter to the request:
curl --location 'http://quotes.test/api/quotes?refresh=true' \
--header 'Authorization: Bearer [TOKEN]'
To run the tests, you can use the following command:
php artisan test
This API implementation is a simple example and is not intended for production use. It is a demonstration of how to create a simple API with Laravel that was completed with a short limit of time.
There are multiple improvements that can be made, such as:
- Using a proper authentication system such as Sanctum or Passport
- Adding more robust validation
- Adding some unit tests (limited myself early on by using configs within the driver class, so unit tests were not possible).