Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

README.md

restapi

A REST API for managing books — the first intermediate project in the go-space learning series.


Usage

go run .

Server starts on http://localhost:8080.

Endpoints

# 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

Example Response

{"id":1,"title":"The Go Programming Language","author":"Donovan","year":2015}

Concepts Covered

  • 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

Go Level Concepts