# External APIs for Web Applications

Free APIs that work directly from the browser (no auth, CORS-enabled):

## Geography & Location

* **OpenStreetMap Nominatim** for geocoding: `https://nominatim.openstreetmap.org/search?q={place}&format=json&limit=1`
* **REST Countries API** for country data: `https://restcountries.com/v3.1/all` or `https://restcountries.com/v3.1/name/{country}`
* **IP Geolocation**: `https://freegeoip.app/json/` (returns location data for current IP)

## Reference & Knowledge

* **Wikipedia API** for knowledge data: `https://en.wikipedia.org/api/rest_v1/page/summary/{title}`
* **Open Library API** for books: `https://openlibrary.org/api/books?bibkeys=ISBN:{isbn}&format=json`
* **MusicBrainz** for music metadata: `https://musicbrainz.org/ws/2/artist/{id}?fmt=json`

## Weather & Environment

* **Open-Meteo** (global, no key): `https://api.open-meteo.com/v1/forecast?latitude={lat}&longitude={lon}&current_weather=true&daily=temperature_2m_max,temperature_2m_min&timezone=auto`
  - Covers the entire world, returns current + daily/hourly forecasts
  - Geocoding helper: `https://geocoding-api.open-meteo.com/v1/search?name={city}&count=1`
* **National Weather Service** (US only):
  1. Get office: `https://api.weather.gov/points/{lat},{lon}` -> returns `{properties: {forecast: "forecastUrl"}}`
  2. Get weather: Call the forecastUrl -> returns `{properties: {periods: [{temperature, shortForecast, windSpeed}]}}`

Prefer Open-Meteo for global coverage. Use NWS only for US-specific detail.

## Developer & Tech

* **GitHub API** (public endpoints): `https://api.github.com/repos/{owner}/{repo}`, `/users/{user}`, `/repos/{owner}/{repo}/issues`
  - Returns repo stats, issues, commits, user profiles
  - Rate limit: 60 req/hour unauthenticated
* **Hacker News API**: `https://hacker-news.firebaseio.com/v0/topstories.json`, `/v0/item/{id}.json`
  - Stories, comments, user profiles, polls — all public
* **PyPI** for Python packages: `https://pypi.org/pypi/{package}/json`
  - Package metadata, versions, download stats
* **npm registry**: `https://registry.npmjs.org/{package}`
  - Package metadata, versions, dependencies
* **cdnjs API**: `https://api.cdnjs.com/libraries?search={query}&fields=name,version,description`
  - Search JavaScript libraries, get CDN URLs

## Social & Content

* **Bluesky / AT Protocol**: `https://public.api.bsky.app/xrpc/app.bsky.feed.getAuthorFeed?actor={handle}`, `app.bsky.actor.getProfile?actor={handle}`
  - Public posts, profiles, threads — no auth for read-only
* **Reddit** (JSON trick): `https://www.reddit.com/r/{subreddit}/hot.json?limit=10`
  - Append `.json` to any Reddit URL for structured data
  - Rate limited, add `?raw_json=1` to avoid HTML entities
* **Mastodon**: `https://{instance}/api/v1/timelines/public?limit=20`
  - Public timeline from any Mastodon instance

## Fun & Entertainment

* **PokeAPI** for Pokemon data: `https://pokeapi.co/api/v2/pokemon/{name}`
* **Dog images**: `https://dog.ceo/api/breeds/image/random`
* **Cat images**: `https://cataas.com/cat` (returns image) or `https://catfact.ninja/fact` (returns cat fact)
* **Chuck Norris jokes**: `https://api.chucknorris.io/jokes/random`
* **General jokes**: `https://v2.jokeapi.dev/joke/Any`
* **Activity suggestions**: `https://www.boredapi.com/api/activity`
* **Cocktail recipes**: `https://www.thecocktaildb.com/api/json/v1/1/random.php`
* **Random alien sprites** (SVG): `https://www.pixelencounter.com/api/v1/aliens/random`
* **Trivia questions**: `https://opentdb.com/api.php?amount=10&type=multiple`

## Food & Health

* **Open Food Facts** (nutrition): `https://world.openfoodfacts.org/api/v0/product/{barcode}.json`

## Financial

* **Currency conversion**: `https://cdn.jsdelivr.net/npm/@fawazahmed0/currency-api@latest/v1/currencies/usd.json`

## Usage Notes

- Respect rate limits — Nominatim: 1 req/sec, GitHub: 60/hour, Reddit: be gentle
- Image APIs return actual images (for dog/cat APIs, use as img src directly)
- Always handle API failures gracefully with fallback content or error messages
- All listed APIs support CORS for client-side `fetch()` calls
- For APIs with rate limits, cache responses in localStorage when appropriate