Quote API
The Quote API provides access to random quotes, ideal for adding inspiration to your applications or for testing purposes.
Endpoint
https://freeapihub.onrender.com/api/v1/quotesGet quote Data by ID
To retrieve quote data by ID, you can use the following endpoint:
https://freeapihub.onrender.com/api/v1/quotes/:quoteIdReplace : quoteId with the actual quote ID you want to fetch.
Installation
To use the Quote API, you’ll need to install Axios. You can do this using either npm or pnpm:
Note: Run these commands in your project directory to install Axios.
Using npm
npm install axiosUsing pnpm
pnpm add axiosExample Usage
Here’s how to fetch random quote data using Axios:
import axios from "axios";
axios
.get("https://freeapihub.onrender.com/api/v1/quotes")
.then((response) => {
console.log(response.data);
})
.catch((error) => {
console.error("Error fetching data:", error);
});Here’s how to fetch quote data by quoteId using Axios:
import axios from "axios";
const quoteId = "1a2b3c4d"; // Replace with actual quote ID
axios
.get(`https://freeapihub.onrender.com/api/v1/quotes/${quoteId}`)
.then((response) => {
console.log(response.data);
})
.catch((error) => {
console.error("Error fetching data by ID:", error);
});Response Format
Below is a sample JSON response when requesting random quote data:
{
"success": true,
"data": [
{
"id": "e27c6a1b-d8a6-4b45-98bb-1c70ed8cb8d1",
"author": "Albert Einstein",
"content": "Life is like riding a bicycle. To keep your balance, you must keep moving.",
"rate": 5,
"likes": 150,
"dislikes": 2,
"category": "Motivation"
},
{
"id": "f39a4587-6a2f-4b45-9f44-fc7fa1b4e53c",
"author": "Maya Angelou",
"content": "You will face many defeats in life, but never let yourself be defeated.",
"rate": 4,
"likes": 120,
"dislikes": 3,
"category": "Inspiration"
}
],
"message": "All quotes retrieved successfully"
}Error Handling
When using the Quote API, it’s essential to handle potential errors effectively. Below are common error codes you may encounter:
| Error Code | Description |
|---|---|
| 404 | Resource not found |
| 429 | Too many requests (rate limit) |
Example Error Handling
To manage potential errors gracefully, you can use a try...catch block in your Axios requests. Here’s an example of how to implement error handling when fetching quote data:
import axios from "axios";
async function fetchQuote() {
try {
const response = await axios.get(
"https://freeapihub.onrender.com/api/v1/quotes"
);
console.log(response.data);
} catch (error) {
console.error(
"Error fetching quote data: ",
error.response?.data?.message || "An unexpected error occurred."
);
}
}
fetchQuote();Usage Tips
- Utilize the Quote API to add inspiration to your applications or for testing purposes.
- Experiment with different API calls to see the variety of quotes returned, helping you understand the structure and attributes available.
- For a deeper understanding of how to effectively use APIs, refer to the API Usage Guide.
Happy coding with the Quote API! 🎉