
Posted on · 3 min read
Free APIs for React Projects: 20 CORS-Enabled APIs and How to Fetch Them Properly
On this page · 6 sections
A React app runs in the browser, so it can only call APIs that send CORS headers, unless you add a server in between. That rules out a surprising number of APIs. Our directory lists 878 CORS-enabled APIs out of 2,166, and the 20 below are the best for React projects. We checked each one for an Access-Control-Allow-Origin header in October 2026.
This guide also gives you a production-quality data-fetching pattern: a reusable hook with loading and error states and request cancellation, and the right way to handle APIs that need a key, which is never to put it in your React bundle.
#20 free CORS-enabled APIs for React
API | Use it for | Example endpoint |
|---|---|---|
Pokédex, search, pagination | | |
Character grid with filters | | |
Show search and detail pages | | |
Weather dashboard | | |
Currency converter | | |
Crypto price table | | |
Coin detail pages | | |
E-commerce UI, login flow | | |
Shopping cart demo | | |
CRUD and optimistic updates | | |
User directory, avatars | | |
Book search with covers | | |
Image gallery | | |
Quiz app with state machine | | |
Card games | | |
News feed, infinite scroll | | |
Holiday calendar | | |
Image carousel | | |
Random content card | | |
Reader app with comments | |
All of these need no API key.
#The data-fetching hook
Fetching in useEffect has three classic bugs: no loading or error state, state updates after the component unmounts, and race conditions when the input changes faster than responses arrive. This hook handles all three with an AbortController:
import { useEffect, useState } from "react";
export function useFetch(url) {
const [state, setState] = useState({ data: null, error: null, loading: Boolean(url) });
useEffect(() => {
if (!url) return;
const controller = new AbortController();
setState((s) => ({ ...s, loading: true, error: null }));
fetch(url, { signal: controller.signal })
.then((res) => {
if (!res.ok) throw new Error(`HTTP ${res.status}`);
return res.json();
})
.then((data) => setState({ data, error: null, loading: false }))
.catch((error) => {
if (error.name !== "AbortError") setState({ data: null, error, loading: false });
});
return () => controller.abort(); // cancel the stale request when url changes or on unmount
}, [url]);
return state;
}And a component using it, a Pokémon search with all three states:
import { useDeferredValue, useState } from "react";
import { useFetch } from "./useFetch";
export default function Pokedex() {
const [query, setQuery] = useState("pikachu");
const name = useDeferredValue(query.trim().toLowerCase());
const { data, error, loading } = useFetch(
name ? `https://pokeapi.co/api/v2/pokemon/${encodeURIComponent(name)}` : null
);
return (
<div>
<input value={query} onChange={(e) => setQuery(e.target.value)} aria-label="Pokémon name" />
{loading && <p>Loading…</p>}
{error && <p role="alert">Not found ({error.message})</p>}
{data && (
<figure>
<img src={data.sprites.front_default} alt={data.name} width={96} height={96} />
<figcaption>
{data.name} · {data.types.map((t) => t.type.name).join(", ")}
</figcaption>
</figure>
)}
</div>
);
}#Use a data library for real apps
The hook above is great for learning. For production, TanStack Query (or SWR) adds caching, deduplication, background refresh and retries, which matter a lot with rate-limited free APIs:
import { useQuery } from "@tanstack/react-query";
function CryptoPrices() {
const { data, isPending, error } = useQuery({
queryKey: ["prices"],
queryFn: () =>
fetch("https://api.coingecko.com/api/v3/simple/price?ids=bitcoin,ethereum&vs_currencies=usd").then((r) => {
if (!r.ok) throw new Error(`HTTP ${r.status}`);
return r.json();
}),
refetchInterval: 60_000, // once a minute is plenty
staleTime: 30_000,
});
if (isPending) return <p>Loading…</p>;
if (error) return <p>Couldn't load prices.</p>;
return <p>BTC ${data.bitcoin.usd} · ETH ${data.ethereum.usd}</p>;
}In Next.js or another React framework with server components, you can often skip client fetching entirely: fetch on the server, cache the result, and send HTML.
#What about APIs that need a key?
Never put a secret API key in React code. Environment variables don't hide it. Vite inlines any VITE_* variable, and Create React App inlines REACT_APP_*, so the key ends up in your JavaScript bundle where anyone can read it.
Instead, put a small proxy on the server. In Next.js that's a route handler:
// app/api/weather/route.js (runs on the server; the key never reaches the browser)
export async function GET(request) {
const city = new URL(request.url).searchParams.get("city") ?? "London";
const res = await fetch(
`https://api.weatherapi.com/v1/current.json?key=${process.env.WEATHERAPI_KEY}&q=${encodeURIComponent(city)}`,
{ next: { revalidate: 600 } } // cache for 10 minutes
);
return Response.json(await res.json(), { status: res.status });
}Your component then calls /api/weather?city=Paris. The same pattern works as a Vercel, Netlify or Cloudflare function for a plain Vite app. A proxy also fixes CORS for APIs that don't support it, since the server makes the request.
#React project ideas by API
- Pokédex (PokéAPI): search, pagination, type filters, a favourites list in
localStorage. - Weather dashboard (Open-Meteo): geolocation, unit toggle, 7-day chart.
- Crypto tracker (CoinGecko): sortable table, sparkline charts, 60-second refresh.
- Book shelf (Open Library): search with debounce, covers, a "want to read" list.
- Quiz game (Open Trivia): a
useReducerstate machine, timer and score. - Shop (DummyJSON or FakeStoreAPI): product grid, cart context, checkout form, login with JWT.
Find more on our live list of free APIs for frontend projects, ranked daily by uptime and response time.
#FAQ
#Which free APIs work with React without a backend?
Any API that sends CORS headers and needs no key: PokéAPI, Open-Meteo, Frankfurter, CoinGecko, DummyJSON, Open Library and the others in the table above.
#How do I fix a CORS error in React?
You can't fix it in React code. Either use an API that supports CORS, or call the API through your own server or serverless function, which isn't subject to CORS.
#Can I hide an API key in a React app with .env?
No. Vite and Create React App embed those variables in the client bundle. Keep keys on a server and proxy the requests.
#Should I use fetch or axios in React?
fetch is built in and enough for most apps. For caching and refetching, use TanStack Query or SWR on top of either.