Skip to content

StarLance-Squad/todo-list-service

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

50 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

codecov

todo-list-service

Todo List Application Service. FullStack application

Echo - High performance, extensible, minimalist Go web framework


Up local environment

Make sure if you have a Golang installed. If not install it - https://go.dev/dl/

go version
  1. Update .env file with your local environment variables
  2. Run the following command to start the server
go mod tidy
go list -m all
go run ./cmd

Build the application

go build -o todo-list-service ./cmd

Run the application

./todo-list-service

API requests for Unix Shell with cURL

Register a new User

curl -X POST http://localhost:8000/authentication/register \
     -H 'Content-Type: application/json' \
     -d '{
           "username": "zelenchuk",
           "email": "[email protected]",
           "password": "root_admin"
         }'

Login User

curl -X POST http://localhost:8000/authentication/login \
     -H "Content-Type: application/json" \
     -d '{
           "username": "newuser",
           "password": "mypassword"
         }'

Who I am

curl -X GET -H "Authorization: Bearer [Your_JWT_Token]" http://localhost:8000/authentication/whoiam

JSON response:

{
  "admin": false,
  "exp": 1704704665,
  "userId": 52,
  "username": "zelenchuk"
}

Create a Todo

curl -X POST http://localhost:8000/todos \
     -H 'Content-Type: application/json' \
     -H 'Authorization: Bearer [Your_JWT_Token]' \
     -d '{"Title": "Sample Todo", "Description": "This is a sample todo item", "Completed": false}'

Get all Todos

curl -X GET http://localhost:8000/todos \
     -H 'Content-Type: application/json' \
     -H "Authorization: Bearer [Your_JWT_Token]"

Execution Methods for Windows PowerShell


Creating a User

$body = @{
    Username = "example"
    Email = "[email protected]"
    Password = "password"
} | ConvertTo-Json

Invoke-WebRequest -Uri "http://localhost:8000/users" -Method Post -ContentType "application/json" -Body $body

User Login

$body = @{
    username = "example"
    password = "password"
}

Invoke-WebRequest -Uri "http://localhost:8000/login" -Method Post -ContentType "application/x-www-form-urlencoded" -Body $body

Creating a Todo

$headers = @{
    Authorization = "Bearer <token>"
    ContentType   = "application/json"
}

$body = @{
    Title       = "Sample Todo"
    Description = "This is a sample todo item"
    Completed   = $false
} | ConvertTo-Json

Invoke-WebRequest -Uri "http://localhost:8000/todos" -Method Post -Headers $headers -Body $body

Getting all Todos

$headers = @{
    Authorization = "Bearer <token>"
}

Invoke-WebRequest -Uri "http://localhost:8000/todos" -Headers $headers

Deleting a Todo

$headers = @{
    Authorization = "Bearer <token>"
}

Invoke-WebRequest -Uri "http://localhost:8000/todos/<todo_id>/<user_id>" -Method Delete -Headers $headers

Update Todo

$headers = @{
    Authorization = "Bearer <token>"
    "Content-Type" = "application/json"
}

$body = @{
    Title = "Updated Title"
    Description = "Updated Description"
    Completed = $true
} | ConvertTo-Json

Invoke-WebRequest -Uri "http://localhost:8000/todos/<todo_id>/<user_id>" -Method Put -Headers $headers -Body $body

Production API


Register User

curl -X POST https://desolate-anchorage-72827-298f3197b035.herokuapp.com/authentication/register \
     -H 'Content-Type: application/json' \
     -d '{
           "username": "zelenchuk",
           "email": "[email protected]",
           "password": "root_admin"
         }'

Login User

curl -X POST https://desolate-anchorage-72827-298f3197b035.herokuapp.com/authentication/login \
     -H "Content-Type: application/json" \
     -d '{
           "username": "newuser",
           "password": "mypassword"
         }'

Who I am

curl -X GET -H "Authorization: Bearer [Your_JWT_Token]" https://desolate-anchorage-72827-298f3197b035.herokuapp.com/authentication/whoiam

JSON response:

{
  "admin": false,
  "exp": 1704704665,
  "userId": 52,
  "username": "zelenchuk"
}

Create a Todo

curl -X POST https://desolate-anchorage-72827-298f3197b035.herokuapp.com/todos \
     -H 'Content-Type: application/json' \
     -H 'Authorization: Bearer [Your_JWT_Token]' \
     -d '{"Title": "Sample Todo", "Description": "This is a sample todo item", "Completed": false}'

Get all Todos

curl -X GET https://desolate-anchorage-72827-298f3197b035.herokuapp.com/todos \
     -H 'Content-Type: application/json' \
     -H "Authorization: Bearer [Your_JWT_Token]"

Releases

No releases published

Packages

No packages published

Languages