I know, it's another todo app. Oh well, it's a good way to get familiar with API development using a new language
Create a .env
file using the .env.schema
. Make sure all of the values are filled out.
Then in the terminal run go run main.go
Create an account, saved to database. JWT response
POST - /api/v1/users/signup
Name | Type | Required |
---|---|---|
String |
true |
|
password | String |
true |
{
"email": "user@email.com",
"password": "abc123"
}
{
"message": "User created",
"status": true,
"data": {
"ID": 2,
"CreatedAt": "2018-12-20T15:15:19.489462-05:00",
"UpdatedAt": "2018-12-20T15:15:19.489462-05:00",
"email": "user@email.com",
"token": "..."
}
}
Log into an existing account. JWT response
POST - /api/v1/users/login
Name | Type | Required |
---|---|---|
String |
true |
|
password | String |
true |
{
"email": "user@email.com",
"password": "abc123"
}
{
"message": "Logged in",
"status": true,
"data": {
"ID": 2,
"CreatedAt": "2018-12-20T15:15:19.489462-05:00",
"UpdatedAt": "2018-12-20T15:15:19.489462-05:00",
"email": "user@email.com",
"token": "..."
}
}
Save a todo to the database.
POST - /api/v1/todos/
Name | Type | Required |
---|---|---|
Authorization | Bearer {Token} | true |
Name | Type | Required |
---|---|---|
value | String |
true |
{
"value": "I am test 2"
}
{
"message": "Todo Saved",
"status": true,
"data": {
"ID": 4,
"CreatedAt": "2018-12-20T20:21:40.772308-05:00",
"UpdatedAt": "2018-12-20T20:21:40.772308-05:00",
"DeletedAt": null,
"value": "I am test 2",
"completed": false,
"user_id": 1
}
}
Retrieve all of your todos from the database
GET - /api/v1/todos/
Name | Type | Required |
---|---|---|
Authorization | Bearer {Token} | true |
{
"data": [
{
"ID": 1,
"CreatedAt": "2018-12-20T19:44:03.477372-05:00",
"UpdatedAt": "2018-12-20T19:44:03.477372-05:00",
"DeletedAt": null,
"value": "I am todo",
"completed": false,
"user_id": 1
}
],
"message": "Success",
"status": true
}
Retrieve a single todo from the database
GET - /api/v1/todos/{id}
Name | Value | Required |
---|---|---|
Authorization | Bearer {Token} | true |
Name | Type | Required | Description |
---|---|---|---|
id | Int |
true |
ID of Todo |
{
"data": {
"ID": 7,
"CreatedAt": "2018-12-20T20:40:55.647052-05:00",
"UpdatedAt": "2018-12-20T20:40:55.647052-05:00",
"DeletedAt": null,
"value": "I am test 3",
"completed": false,
"user_id": 3
},
"message": "Todo Found",
"status": true
}
Edit and save a todo to the database.
PATCH - /api/v1/todos/{id}
Name | Value | Required |
---|---|---|
Authorization | Bearer {Token} | true |
Name | Type | Required | Description |
---|---|---|---|
id | Int |
true |
ID of Todo |
Name | Type | Required |
---|---|---|
value | String |
true |
{
"completed": true
}
{
"data": {
"ID": 2,
"CreatedAt": "2018-12-20T19:45:15.128387-05:00",
"UpdatedAt": "2018-12-20T19:45:15.128387-05:00",
"DeletedAt": null,
"value": "I am test",
"completed": true,
"user_id": 1
},
"message": "Todo Updated",
"status": true
}
Remove your todo from the database
DELETE - /api/v1/todos/{id}
Name | Value | Required |
---|---|---|
Authorization | Bearer {Token} | true |
Name | Type | Required | Description |
---|---|---|---|
id | Int |
true |
ID of Todo |
Name | Type | Required |
---|---|---|
value | String |
true |
{
"message": "Todo does not exist",
"status": false
}