GO_API

module
v0.0.0-...-4a724ca Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 17, 2020 License: MIT

README

Build Status codecov reliability rating security rating

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

Directories

Path Synopsis
cmd
goapi command
pkg
api

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL