A REST API for managing books and authors like a librarian.
openapi.yaml
: API specification – refer to this for request/response formatsinternal/api/types.go
: Request/response types and validationinternal/api/handlers.go
: HTTP handlers using standardnet/http
internal/db/
: SQLC-generated database codeinternal/db/migrations/
: Database schema and seed data
- Authors and Books:
GET /api/v1/authors
: List all authorsGET /api/v1/books
: List all booksPOST /api/v1/books
: Create a new bookPUT /api/v1/books/{id}
: Update a bookDELETE /api/v1/books/{id}
: Delete a bookGET /api/v1/authors/{id}/stats
: Get author statistics
Ensure the following tools are installed on your system:
# Install dependencies and tools
make setup
# Start PostgreSQL
make docker-up
# Run migrations
make migrate-up
# Run the API
make run
# API will be available at http://localhost:8080
- Use
make run
to restart the API after changes - See
Makefile
for all available commands - PostgreSQL is accessible at localhost:5432
- Database credentials: bookstore/bookstore
- Each time you run
make migrate-up
, the database is seeded with:- A set of authors and books
- 10,000 randomized book sales records
- Note: Sales data will be different after each migration