Simple GOLang REST API
Simple RESTful API to create, read, update and delete books.
Quick Start
# Make .env file
cp .env.example .env
# Run Docker-compose with PSQL
docker-compose up
# Run migrations
make migrate
# Build app
go build github.com/sotanodroid/GO_API/cmd/goapi
#Or just run pre-built app
./main
Server would be available on port 8000
Endpoints
Get All Books
GET api/books
# Response
[
    {
        "id": 1,
        "isbn": "153223",
        "title": "Book_One",
        "author": {
            "id": 1,
            "firstname": "John",
            "lastname": "Doe"
        }
    },
    {
        "id": 2,
        "isbn": "153235",
        "title": "Book Two",
        "author": {
            "id": 2,
            "firstname": "Steve",
            "lastname": "Smith"
        }
    }
]
Get Single Book
GET api/books/{id}
# Response
{
    "id":1,
    "isbn":"153223",
    "title":"Book_One",
    "author":{
        "id":1,
        "firstname":"John",
        "lastname":"Doe"
    }
}
Delete Book
DELETE api/books/{id}
Response:
"Deleted"
Create Book
POST api/books
# Request sample
{
  "isbn":"4545454",
  "title":"Book Three",
  "author": {
      "firstname":"John",
      "lastname":"Doe"
    }
}
Update Book
PUT api/books/{id}
# Request sample
{
  "isbn":"4545454",
  "title":"Updated Title"
}
Tests:
make test