This project is an example REST API that shows how to work with local and DB. As an architecture, Layered Architecture used.
This API contains 2 services: Book, Author
On the root folder:
go run .You need to have Docker Compose on your machine, then on the root folder:
- Building images
docker compose build --no-cachedocker compose up
- Coverage
- Run Tests:
go test -v ./...- Calculate coverage
go test -cover ./...- Export coverage file as html
go test -coverprofile c.out ./...
go tool cover -html=c.outAPI has 2 version.
- Storing data locally <base_url>/api/v1
- Storing data in DB <base_url>/api/v2
- GET ALL BOOKS
Request: GET /api/v1/books
Response: {
id: string
title: string
description: string
publication_date: string
authorIDs: string[]
}[]- GET SINGLE BOOK WITH
id
Request: GET /api/v1/book/:id
Response: {
id: string
title: string
description: string
publication_date: string
authorIDs: string[]
}- SEARCH BOOKS (searching for
titleordescriptionorauthorId)
Request: GET /api/v1/book/search/:search_text
Response: {
id: string
title: string
description: string
publication_date: string
authorIDs: string[]
authors {
id: string
name: string
surname: string
}[]
}[]- CREATE A BOOK
Request: POST /api/v1/book
body {
title: string
description: string
publication_date: string
authorIDs: string[]
}
Response: {
id: string
title: string
description: string
publication_date: string
authorIDs: string[]
}- UPDATE EXISTING BOOK WITH
id
Request: PUT /api/v1/book/:id
body {
title: string
description: string
publication_date: string
authorIDs: string[]
}
Response: {
id: string
title: string
description: string
publication_date: string
authorIDs: string[]
}- DELETE EXISTING BOOK WITH
id
Request: DELETE /api/v1/book/:id
Response: {
id: string
title: string
description: string
publication_date: string
authorIDs: string[]
}- GET ALL AUTHORS
Request: GET /api/v1/authors
Response: {
id: string
name: string
surname: string
}[]- GET SINGLE AUTHOR WITH
id
Request: GET /api/v1/author/:id
Response: {
id: string
name: string
surname: string
}- SEARCH AUTHORS (searching for
nameorsurname)
Request: GET /api/v1/author/search/:search_text
Response: {
id: string
name: string
surname: string
books: {
id string
title string
description string
publication_date string
authorIDs string[]
}[]
}[]- CREATE AN AUTHOR
Request: POST /api/v1/author
body {
name: string
surname: string
}
Response: {
id: string
name: string
surname: string
}- UPDATE EXISTING AUTHOR WITH
id
Request: PUT /api/v1/author/:id
body {
name: string
surname: string
}
Response: {
id: string
name: string
surname: string
}- DELETE EXISTING AUTHOR WITH
id
Request: DELETE /api/v1/author/:id
Response: {
id: string
name: string
surname: string
}For version 2, DB is not fully implemented, but these 2 endpoints were implemented to show how using MySQL DB using in the code.
- GET ALL BOOKS
Request: GET /api/v2/books
Response: {
id: string
title: string
description: string
publication_date: string
authorIDs: string[]
}[]- GET ALL AUTHORS
Request: GET /api/v2/authors
Response: {
id: string
name: string
surname: string
}[]