项目作者: sotanodroid

项目描述 :
Golang implementation API
高级语言: Go
项目地址: git://github.com/sotanodroid/GO_API.git
创建时间: 2019-11-03T10:53:17Z
项目社区:https://github.com/sotanodroid/GO_API

开源协议:MIT License

下载


Build Status codecov reliability rating security rating

Simple GOLang REST API

Simple RESTful API to create, read, update and delete books.

Quick Start

  1. # Make .env file
  2. cp .env.example .env
  1. # Run Docker-compose with PSQL
  2. docker-compose up
  1. # Run migrations
  2. make migrate
  1. # Build app
  2. go build github.com/sotanodroid/GO_API/cmd/goapi
  3. #Or just run pre-built app
  4. ./main

Server would be available on port 8000

Endpoints

Get All Books

  1. GET api/books
  2. # Response
  3. [
  4. {
  5. "id": 1,
  6. "isbn": "153223",
  7. "title": "Book_One",
  8. "author": {
  9. "id": 1,
  10. "firstname": "John",
  11. "lastname": "Doe"
  12. }
  13. },
  14. {
  15. "id": 2,
  16. "isbn": "153235",
  17. "title": "Book Two",
  18. "author": {
  19. "id": 2,
  20. "firstname": "Steve",
  21. "lastname": "Smith"
  22. }
  23. }
  24. ]

Get Single Book

  1. GET api/books/{id}
  2. # Response
  3. {
  4. "id":1,
  5. "isbn":"153223",
  6. "title":"Book_One",
  7. "author":{
  8. "id":1,
  9. "firstname":"John",
  10. "lastname":"Doe"
  11. }
  12. }

Delete Book

  1. DELETE api/books/{id}
  2. Response:
  3. "Deleted"

Create Book

  1. POST api/books
  2. # Request sample
  3. {
  4. "isbn":"4545454",
  5. "title":"Book Three",
  6. "author": {
  7. "firstname":"John",
  8. "lastname":"Doe"
  9. }
  10. }

Update Book

  1. PUT api/books/{id}
  2. # Request sample
  3. {
  4. "isbn":"4545454",
  5. "title":"Updated Title"
  6. }

Tests:

  1. make test