Skip to content

minhtrifit/golang-rest-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Golang Restfull API Docker Document

RUN DOCKER: docker-compose -f .\docker-compose.yml up

RUN SERVER: go run main.go

Open Mongo-express browser: https://localhost:8081

Username: root

Password: root

API Listing

Get All Albums:

Request

GET: https://localhost:5000/albums

Response

{
  "data": [
    {
      "_id": "65348f16fea56e0d94903eab",
      "artist": "John Coltrane",
      "id": 1,
      "price": 56.99,
      "title": "Blue Train"
    },
    {
      "_id": "65348f2efea56e0d94903ead",
      "artist": "Gerry Mulligan",
      "id": 2,
      "price": 17.99,
      "title": "Blue Train"
    },
    {
      "_id": "65348f4cfea56e0d94903eaf",
      "artist": "Sarah Vaughan",
      "id": 3,
      "price": 39.99,
      "title": "Sarah Vaughan and Clifford Brown"
    }
  ],
  "status": 200
}

Get album by id

Request Body

GET: https://localhost:5000/albums/query?id=1

Response

{
  "data": {
    "id": 1,
    "title": "Blue Train",
    "artist": "John Coltrane",
    "price": 56.99
  },
  "message": "Find album successfully",
  "status": 200
}

Insert New Album:

POST: https://localhost:5000/albums/add

Request Body

{
  "title": "Nơi Nào  Tình Yêu",
  "artist": "Minh Trí",
  "price": 150.00
}

Response

{
  "data": {
    "id": 4,
    "title": "Nơi Nào Có Tình Yêu",
    "artist": "Minh Trí",
    "price": 150
  },
  "message": "Insert album successfully",
  "status": 200
}

Delete Album By Id:

DELETE: https://localhost:5000/albums/delete

Request Body

{
  "id": 4
}

Response

{
  "albums": 4,
  "message": "Delete album successfully",
  "status": 200
}

Edit Album:

PUT: https://localhost:5000/albums/edit

Request Body

{
  "id": 4,
  "title": "Nơi Không  Em 2",
  "artist": "Minh Trí",
  "price": 150.69
}

Response

{
  "data": {
    "MatchedCount": 1,
    "ModifiedCount": 1,
    "UpsertedCount": 0,
    "UpsertedID": null
  },
  "message": "Edit album successfully",
  "status": 200
}

Showcases:

GET Method

GET

POST Method

POST

About

Restfull API With Golang + Docker

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published