Golang implementation API
Simple RESTful API to create, read, update and delete books.
# 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
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 api/books/{id}
# Response
{
"id":1,
"isbn":"153223",
"title":"Book_One",
"author":{
"id":1,
"firstname":"John",
"lastname":"Doe"
}
}
DELETE api/books/{id}
Response:
"Deleted"
POST api/books
# Request sample
{
"isbn":"4545454",
"title":"Book Three",
"author": {
"firstname":"John",
"lastname":"Doe"
}
}
PUT api/books/{id}
# Request sample
{
"isbn":"4545454",
"title":"Updated Title"
}
make test