Skip to content

FelineFantasy/CatFactsAPI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

17 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🐱 CatFactsAPI

API for getting random facts and information about cat breeds in English.

πŸ“‹ Description

CatFactsAPI is a simple and lightweight REST API built with FastAPI that returns random facts about cats and breed information. Perfect for educational projects, test applications, or just for fun.

πŸš€ Features

  • βœ… Random cat facts
  • βœ… 100+ unique facts in the database
  • βœ… Cat breed information
  • βœ… Get fact or breed by ID
  • βœ… Fact length information
  • βœ… Automatic documentation via Swagger UI
  • βœ… English-language API

πŸ“¦ Installation

Requirements

  • Python 3.8+
  • pip

Installation Steps

  1. Clone the repository:
git clone https://github.com/FelineFantasy/CatFactsAPI
cd CatFactsAPI
  1. Install dependencies:
pip install -r requirements.txt

πŸƒ Running

Local Run

Start the server using Uvicorn:

uvicorn main:app --reload

The server will be available at: http://localhost:8000

Online Version

The API is already deployed and available at: https://catfactsapi.onrender.com

πŸ“‘ API Endpoints

Cat Facts

Method Endpoint Description
GET / API information
GET /fact Random fact
GET /facts?limit=5 Multiple random facts
GET /fact/{id} Fact by ID (0–99)

Cat Breeds

Method Endpoint Description
GET /breed Random breed
GET /breeds?limit=5 Multiple breeds
GET /breed/{id} Breed by ID (0–9)

πŸ“– Documentation

Interactive documentation is available at:

When running locally:

πŸ§ͺ Usage Examples

cURL

# Random fact
curl https://catfactsapi.onrender.com/fact

# Random breed
curl https://catfactsapi.onrender.com/breed

# 3 random facts
curl https://catfactsapi.onrender.com/facts?limit=3

# Fact by ID
curl https://catfactsapi.onrender.com/fact/42

# Breed by ID
curl https://catfactsapi.onrender.com/breed/5

Python

import requests

# Random fact
response = requests.get("https://catfactsapi.onrender.com/fact")
data = response.json()
print(data["fact"])

# Random breed
response = requests.get("https://catfactsapi.onrender.com/breed")
data = response.json()
print(data["breed"], data["country"])

JavaScript (Fetch API)

// Random fact
fetch('https://catfactsapi.onrender.com/fact')
  .then(response => response.json())
  .then(data => console.log(data.fact));

// Random breed
fetch('https://catfactsapi.onrender.com/breed')
  .then(response => response.json())
  .then(data => console.log(data.breed, data.country));

πŸ“ Project Structure

CatFactsAPI/
β”œβ”€β”€ main.py           # Main application file
β”œβ”€β”€ facts.json        # Cat facts database (100+)
β”œβ”€β”€ breeds.json       # Cat breeds database (10+)
β”œβ”€β”€ requirements.txt  # Project dependencies
└── README.md         # Documentation

πŸ›  Technologies

  • FastAPI β€” Modern web framework for building APIs
  • Uvicorn β€” ASGI server
  • Render β€” Hosting (live version)

πŸ‘€ Author

  • FelineFantasy
  • License: MIT

πŸ”— Links


Made with ❀️ for cat lovers

About

REST API for random cat facts and breed information built with FastAPI

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages