A REST API for managing books — the first intermediate project in the go-space learning series.
go run .Server starts on http://localhost:8080.
# List all books
curl http://localhost:8080/books
# Get a book by ID
curl http://localhost:8080/books/1
# Add a new book
curl -X POST http://localhost:8080/books \
-H "Content-Type: application/json" \
-d '{"title":"Clean Code","author":"Martin","year":2008}'
# Delete a book
curl -X DELETE http://localhost:8080/books/1{"id":1,"title":"The Go Programming Language","author":"Donovan","year":2015}- Struct tags for JSON field mapping (
json:"title") - JSON encoding and decoding with
encoding/json - Handler methods on structs for shared state
- HTTP status codes (200, 201, 400, 404)
- Routing GET/POST/DELETE on the same path via
r.Method - Manual URL path parsing for path parameters
- Two-value returns
(Book, bool)for found/not found pattern