Project: Blog Reader With API
Introduction
Build a blog reader SPA that loads posts from a REST API—paginated list, detail by slug, loading/error/empty states, and React Router navigation. Connect to FastAPI REST CRUD, Django blog REST, or JSONPlaceholder.
Prerequisites
Sister project: Vue Blog Reader—same API contract.
Architecture
text
PostListPage → GET /api/v1/posts?page=1
PostDetailPage → GET /api/v1/posts/:slug
↑
usePosts / usePost hooks
↑
api/client.tsTypes
src/types/post.ts:
typescript
Hooks
src/hooks/usePosts.ts:
tsx
src/hooks/usePost.ts:
tsx
Routes
tsx
{
path: "posts",
element: <PostListPage />,
},
{
path: "posts/:slug",
element: <PostDetailPage />,
},PostListPage
tsx
PostDetailPage
tsx
CORS Checklist
| Dev | Config |
|---|---|
| Vite proxy | server.proxy in vite.config.ts |
| Direct API | Backend CORS middleware |
| Production | Nginx same-origin proxy |
Deliverables
- List with loading/error/empty
- Navigate to
/posts/:slug - Detail shows title and body
- Pagination works
- Refresh on detail URL in production build
FAQ
No slug on backend?
Use /posts/:id and adjust hooks.
JSONPlaceholder mock?
Map id to slug in adapter.
404 on refresh?
Nginx try_files — Build and Deploy.