Creating Simple Api

this application is a simple api application using golang and mysql

go version

  • 1.5

library required

-- note: You don't need to install the libraries one by one, because in the project there is a go mod, when the project is run for the first time it will automatically download all the libraries needed

Installation

Using Makefile Command

  • deploy app in docker
 $~ make deploy
  • view logs of running projects
$~ make logs
  • remove project in docker
$~ make clear

Using Docker Command

  • deploy app in docker
$~ docker-compose up -d

Local app access

  • url
localhost:7081

Access phpmyadmin

  • url
localhost:8085
  • user login phpmyadmin
user: root
password: pass123

Without Docker

  • change file .env.example name to .env
  • Setting database mysql in .env file
  • run in terminal
  $~ go run main.go

Testing

Method POST : User Registered

{{BASE_URL}}/user/register
  • Request Body
{
    "name": "andi",
    "email": "andi@example.com",
    "password": "123456"
}

Methode POST : User login

{{BASE_URL}}/user/login
  • Request Body
{
    "email": "andi@example.com",
    "password": "123456"
}
  • Respon body
{
    "success": true,
    "message": "Success",
    "data": {
        "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwYXNzIjoiJDJhJDEwJEQuUS9oM3FTT2dVbXFPSGNvdjdCbS5VbEdUUkl2UC52MW13WjkuTnNGVjFqN3BRLm1VdnVHIiwidXNlcl9pZCI6MX0.pjVi1Gn1ddokTsok5EQPDO8d8n60JIiZq3rB2Pl_kVI"
    }
}

each account will get a different token code, you can copy the token code in the response body then enter it into the authorization section then select bearer token input bearer

Method POST : Add question

{{BASE_URL}}/question
  • Request Body
{
    "question": "lorem ipsum dolor sit amet consectetur adipiscing elit"
}

Method GET : Get all question

{{BASE_URL}}/question?page=1&limit=20

Method GET : Get detail question

{{BASE_URL}}/question/{{UUID}}

Method PUT : Update question

{{BASE_URL}}/question/{{UUID}}
  • request body
{
    "question": "INI UNTUK UPDATE 3",
    "is_active": true
}

Methode DELETE : Delete question

{{BASE_URL}}/question/{{UUID}}