A simple web application that fetches and displays random quotes using the Quotable API. This project demonstrates basic API fetching using JavaScript's Fetch API and showcases a modern UI with a glassmorphism effect.
- Fetches random quotes from an external API
- Sleek UI with glassmorphism effect
- Responsive design for various screen sizes
- Loading state handling
- Error handling for failed API requests
Note: The live demo may experience CORS errors on some devices. For the best experience, we recommend running the project locally. We welcome contributions to help resolve this issue!
- HTML5
- CSS3 (with glassmorphism effects)
- JavaScript (ES6+)
- Fetch API
- Quotable API
Quote-Generator/
├── api/
│ └── corserrorfix.js # Server middleware to handle CORS errors
├── files/
│ ├── script.js # JavaScript code: Logic behind page working
│ └── style.css # CSS code: Page styles
├── index.html # HTML file: Page structure
├── README.md # Project documentation
└── LICENSE # MIT License
-
API Integration: The application uses the Fetch API to make an asynchronous GET request to the Quotable API endpoint (
https://api.quotable.io/random). -
Promise Handling: Promises returned by the Fetch API are handled using async/await syntax for cleaner code.
-
DOM Manipulation: The fetched quote and author information are dynamically inserted into the page.
-
Event Listeners: The application listens for the DOM content loaded event and button click events to trigger quote fetching.
-
Error Handling: Try/catch blocks are used to handle potential errors during the API fetch process.
The HTML provides the basic structure of the application:
- Container for the quote and author text
- Button to generate new quotes
- Links to external CSS and JavaScript files
The CSS file defines the visual appearance of the application:
- Implements a glassmorphism effect (translucent, blurred background)
- Creates a responsive layout
- Applies hover and active state animations
- Sets up the background image
The JavaScript file handles the functionality:
getQuote(): Asynchronous function to fetch and display a random quotedisplayLoadingState(): Updates the UI during loading- Event listeners to handle user interactions
This middleware helps resolve Cross-Origin Resource Sharing (CORS) errors that may occur when fetching quotes from the external API.
This project demonstrates several important web development concepts:
- API Fetching: How to use the Fetch API to retrieve data from external sources
- Asynchronous JavaScript: Using async/await for cleaner promise handling
- Error Handling: Implementing try/catch blocks for robust error management
- DOM Manipulation: Dynamically updating page content
- Modern CSS Effects: Implementing glassmorphism and responsive design
- Event Handling: Setting up event listeners for user interaction
- A modern web browser
- Basic understanding of HTML, CSS, and JavaScript
-
Clone the repository:
git clone https://github.com/ivin-titus/Quote-Generator -
Navigate to the project directory:
cd quote-generator -
Open
index.htmlin your web browser.
You can customize this project by:
- Changing the background: Modify the background image URL in the CSS file
- Styling adjustments: Update colors, fonts, and sizing in the CSS file
- Additional features: Add quote categories, favorites functionality, or social sharing options
We welcome contributions to this project! Here are some ways you can help:
- Fix CORS issues: Help improve the CORS error handling to make the demo work across all devices
- Add new features: Implement quote categories, social sharing, or favorites
- Improve accessibility: Make the application more accessible to all users
- Fix bugs: Address any issues you find while using the application
To contribute:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Quotable API for providing the quotes data
- Unsplash for the background image
- Google Fonts for the Poppins font family
