A simple RESTful API for managing a collection of books, built with Go. This project demonstrates a clean Go project structure, in-memory data storage, and basic HTTP handlers for CRUD operations.
- List Books: Retrieve all books in the library
- Add Book: Add a new book to the collection
- Get Book by ID: Fetch details of a specific book
- Update Book: Edit the title and author of a book
- Language: Go 1.24+
- Framework: net/http (standard library)
- Data Storage: In-memory slice (no external DB)
- API: RESTful endpoints (JSON)
BookLibrary/
├── cmd/
│ └── my_app/
│ └── main.go # Application entry point
├── internal/
│ ├── database/
│ │ └── book_database.go # Book struct & in-memory DB
│ └── handlers/
│ └── handler.go # HTTP handlers for API
├── go.mod
└── README.md
- Go 1.24 or later (https://go.dev/dl/)
- Clone the repository:
git clone <repo-url> cd Go-Book-Library-API
- Download dependencies:
go mod tidy
- Run the server:
The server will start on
cd cmd/my_app go run main.gohttp://localhost:3333.
GET /GetBooks— List all booksPOST /AddBook— Add a new book (JSON body)GET /GetBooks/{id}— Get a book by IDPUT /PutBook/{id}— Update a book by ID (JSON body)
{
"bookId": "string",
"title": "string",
"author": "string"
}This project is licensed under the MIT License.