This project consists of a simple book API written in Go. The API can interact with a Postgresql database and handle books using HTTP POST, GET, and DELETE methods. It runs on Docker with a connected Postgresql DB.
docker-compose up -d
go mod tidy
go run main.go
┌───────────────────────────────────────────────────┐
│ Fiber v2.48.0 │
│ http://127.0.0.1:3000 │
│ (bound on host 0.0.0.0 and port 3000) │
│ │
│ Handlers ............. 6 Processes ........... 1 │
│ Prefork ....... Disabled PID ............. 00000 │
└───────────────────────────────────────────────────┘
- The API will be available at http://localhost:3000 by default.
- The API can be accessed using the specified HTTP methods:
- To add a new book: POST http://localhost:3000/api/new_books
- To get all books: GET http://localhost:3000/api/books
- To get a specific book: GET http://localhost:3000/api/get_book/{book_id}
- To delete a book: DELETE http://localhost:3000/api/delete_book/{book_id}
With this request, you can add a new book to the API. The request body should be in JSON format and include the following properties:
{
"author": "Author Name",
"title": "Book Title",
"publisher": "Publisher"
}
With this request, you can retrieve all books from the API. The result will be in JSON format:
[
{
"id": 1,
"author": "Author 1",
"title": "Book 1",
"publisher": "Publisher 1"
},
{
"id": 2,
"author": "Author 2",
"title": "Book 2",
"publisher": "Publisher 2"
}
]
With this request, you can retrieve a specific book from the API. You need to include the {book_id} parameter in the request.
With this request, you can delete a specific book from the API. You need to include the {book_id} parameter in the request.