Libraria is a sample REST API for books.
Tested with Go 1.13.x. Uses Go Modules.
go test ./...
go run main.go
Following are some example API requests and responses.
Create a book.
curl -s -X POST http://localhost:8080/books -H "Content-Type: application/json" -d "@book_00.json"
curl -s -X POST http://localhost:8080/books -H "Content-Type: application/json" -d "@book_01.json"
{
"author": "George Orwell",
"title": "1984",
"ISBN": "9780451524935",
"language": "English",
"published": "1961-01-01T00:00:00Z",
"listPrice": 999
}
Read all books.
curl -s -X GET http://localhost:8080/books
{
"9780451524935": {
"author": "George Orwell",
"title": "1984",
"ISBN": "9780451524935",
"language": "English",
"published": "1961-01-01T00:00:00Z",
"listPrice": 999
},
"9780553380163": {
"author": "Stephen Hawking",
"title": "A Brief History of Time",
"ISBN": "9780553380163",
"language": "English",
"published": "1998-09-01T00:00:00Z",
"listPrice": 1800
}
}
Read one book.
curl -s -X GET http://localhost:8080/books/9780451524935
{
"author": "George Orwell",
"title": "1984",
"ISBN": "9780451524935",
"language": "English",
"published": "1961-01-01T00:00:00Z",
"listPrice": 999
}
Update a book.
curl -s -X PUT http://localhost:8080/books -H "Content-Type: application/json" -d "@book_01.json"
{
"author": "Stephen Hawking",
"title": "A Brief History of Time",
"ISBN": "9780553380163",
"language": "English",
"published": "1998-09-01T00:00:00Z",
"listPrice": 1800
}
Delete a book.
curl -s -X DELETE http://localhost:8080/books/9780451524935
{}