BookHub
Book catalog with optimistic UI updates and consistent REST API design.

Overview
Built as a deliberate exercise in REST API fundamentals before adding complexity in later projects. Every endpoint returns a consistent response envelope (status, data, message); error responses include machine-readable codes alongside human-readable messages; all mutations return the updated resource rather than a generic success flag. Optimistic updates on the frontend keep the UI responsive — edits appear immediately and roll back cleanly from a pre-mutation snapshot if the API call fails.
What it does
- Consistent API response envelope across all endpoints — predictable shape for every frontend consumer
- Optimistic UI updates with snapshot-based rollback on failure — no re-fetch, no stale data flash
- Search and filter by title, author, and genre
- Cover image management via URL-based storage
- Machine-readable error codes on all failure responses — frontend can differentiate error types without string parsing
Problems and how I solved them
Problem
Ensuring rollback logic was reliable — a failed optimistic update that doesn't revert cleanly leaves the UI in a broken state that's difficult to recover from without a page reload
Fix
Stored pre-mutation state in a local variable before applying the optimistic update; the catch block restores from that snapshot rather than re-fetching — faster recovery and avoids a flash of stale server data