About Facts API
The Facts API provides developers with access to a comprehensive database of verified and interesting facts across multiple categories. Whether you're building an educational app, a trivia game, or just looking to integrate fascinating facts into your website, our API makes it simple.
API Features:
- 200+ curated, interesting facts
- 6 distinct categories: science, history, astronomy, biology, animals, and technology
- Simple RESTful endpoints
- Filter by category, verification status, or use search capabilities
- Each fact includes title, content, source, and year discovered
Get All Facts
Number of facts to return (1-20)
No facts found. Try adjusting your filters or fetching facts.
Get Random Fact
GET /api/facts/random
Click the button to get a random fact.
Get Fact by ID
Enter the ID of the fact you want to retrieve
Enter an ID and click "Fetch Fact" to get a specific fact.
Get Facts by Category
Choose from astronomy, biology, physics, animals, history, or technology
Enter a category and click "Fetch Facts" to get facts for that category.
Search Facts
Search through fact titles and content
Enter search terms and click "Search" to find matching facts.
API Documentation
Get All Facts
GET /api/facts?limit=:limit&verified=:verified
Retrieve a collection of facts with optional filtering.
Parameters:
- limit (optional): Number of facts to return (default: 10)
- verified (optional): Set to 'true' to get only verified facts
Get Random Fact
GET /api/facts/random
Retrieve a single random fact from the database.
Get Fact by ID
GET /api/facts/:id
Retrieve a specific fact by its unique identifier.
Parameters:
- id (required): The numeric ID of the fact
Get Facts by Category
GET /api/facts/category/:category
Retrieve all facts belonging to a specific category.
Parameters:
- category (required): Category name (astronomy, biology, physics, animals, history, or technology)
Search Facts
GET /api/facts/search?q=:query
Search through facts based on a text query.
Parameters:
- q (required): The search query string
Data Types
Fact Object
interface Fact {
id: number;
category: Categories;
title: string;
fact: string;
verified: boolean;
source: string;
year_discovered: number;
interesting_rating: number;
}
Categories
type Categories =
| "astronomy"
| "biology"
| "physics"
| "animals"
| "history"
| "technology";
Getting Started
Our Facts API is free to use and requires no authentication for basic usage. Follow these simple steps to start integrating facts into your application:
1. Make Your First API Call
// Using fetch API fetch('https://f-api.ir/api/facts/random') .then(response => response.json()) .then(data => console.log(data)) .catch(error => console.error('Error:', error));
2. Handle the Response
Each fact is returned in JSON format with the following structure:
{ "id": 42, "category": "astronomy", "title": "Saturn's Rings", "fact": "Saturn's rings are made mostly of water ice particles, with a small amount of rocky debris and dust.", "verified": true, "source": "NASA", "year_discovered": 1610, "interesting_rating": 9 }