This project is a simple RESTful API for fetching random motivational quotes. It uses Flask and Flask-RESTful for API creation and supports CORS for cross-origin requests.
- Fetch random motivational quotes.
- Easy integration with other projects.
- CORS support for cross-origin requests.
- Backend: Flask, Flask-RESTful
- HTTP Requests:
requests
library - Frontend: Bootstrap (for simple UI)
Follow these steps to run the project locally:
-
Clone the repository:
git clone https://github.com/whdev36/quote-api.git cd quote-api
-
Create a virtual environment (optional but recommended):
python -m venv venv source venv/bin/activate # On Windows, use venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
-
Run the application:
python app.py
-
Open your browser and navigate to
http://127.0.0.1:5000
.
- Endpoint:
/api/random
- Method:
GET
- Response:
{ "content": "The only way to do great work is to love what you do.", "author": "Steve Jobs" }
- Endpoint:
/
- A simple HTML page with instructions on how to use the API.
fetch('http://127.0.0.1:5000/api/random')
.then(response => response.json())
.then(data => {
console.log(data.content); // Display the quote
console.log(data.author); // Display the author
})
.catch(error => console.error('Error:', error));
- The API fetches random quotes from
https://api.quotable.io/random
. - If the external API is unreachable, the service returns an error message.
Contributions are welcome! If you encounter any issues or have suggestions, feel free to create a pull request or open an issue.
This project is licensed under the MIT License. See the LICENSE file for details.
Created by whdev36. Feel free to reach out!