This project was born because only 1 reason: I'm learning Golang and trying to apply anything to this project. Summary: A user can create/view/update/delete his tasks. A user can only view his tasks.
- CRUD functions with Mysql
- Middleware to setHeader & Authentication (Using JWT)
- Apply singleton to create database instance
- Retrieve params from POST request (without using Bind a struct)
CRUD functions
Method: POST
Route: /task
- Request (application/json)
- Headers
- Authorization: Bearer [token]
- Body
- title: "Homework" (string required)
- Headers
- Response 200
- Body
{ "error_code": 200, "data": { "id": 1 } }
- Body
- Response 401
- Body
{ "error_code": 401, "error_message": "title is required" }
- Body
Method: GET
Route: /task
Method: GET
Route: /task/:id
Method: PUT
Route: /task/:id
-
Params:
id
-int
: Task ID -
Request (application/json)
- Headers
- Authorization: Bearer [token]
- Body
- title: "Homework" (string)
- done: 1 (int)
- Headers
-
Response 200
Method: DELETE
Route: /task/:id
Hard code with username/password to get token for testing
Method: POST
Route: /login
- Request (application/json)
- Body
- username: "chris" (string)
- password: "123456" (string)
- Body
- Response 200
- Body
{ "message": "You were log in!", "token": "eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiY2hyaXMiLCJleHAiOjE1ODEzMzA1MTAsImp0aSI6IjIifQ.B7IgJBaotq7Y-is0Ba64fW36yzrpcTrwS00wzcWBRzzJDenyelNu23hjLU1H9FKZF30iBH_JycJaAcQW2fch8Q" }
- Body