This is a simple Go REST API for a Settings
service, built on Echo
framework.
To build and run the application, run the following commands:
docker-compose build
docker-compose up -d
The API uses JWT for authentication. To generate a token, run call sign-in endpoint with the following credentials:
username: admin
password: SabziPolo
curl -X GET http://localhost:8090/
{
"message": "Hello!"
}
curl --request POST \
--url http://localhost:8090/signin \
--header 'Content-Type: application/json' \
--data '{
"username": "admin",
"password": "SabziPolo"
}'
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2NzY4OTM3ODUsInVzZXJuYW1lIjoiYWRtaW4ifQ.dh-5OPn_njxoGhpaBeys8ncCnvEPY5UCEx2JZNl7xbo"
}
curl --request POST \
--url http://localhost:8090/settings \
--header 'Authorization: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2NzY4OTM3ODUsInVzZXJuYW1lIjoiYWRtaW4ifQ.dh-5OPn_njxoGhpaBeys8ncCnvEPY5UCEx2JZNl7xbo' \
--header 'Content-Type: application/json' \
--data '{
"key": "new-setting",
"value": "value for the new setting",
"ttl": 6000
}'
{
"key": "new-setting",
"value": "value for the new setting",
"ttl": 6000,
"created_at": "0001-01-01T00:00:00Z",
"updated_at": "0001-01-01T00:00:00Z"
}
curl --request PUT \
--url http://localhost:8090/settings/aa \
--header 'Authorization: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2NzY4OTM3ODUsInVzZXJuYW1lIjoiYWRtaW4ifQ.dh-5OPn_njxoGhpaBeys8ncCnvEPY5UCEx2JZNl7xbo' \
--header 'Content-Type: application/json' \
--data '{
"key": "new-setting",
"value": "this is a modified value",
"ttl": 1000
}'
{
"key": "new-setting",
"value": "this is a modified value",
"ttl": 1000,
"created_at": "0001-01-01T00:00:00Z",
"updated_at": "0001-01-01T00:00:00Z"
}
curl --request GET \
--url http://localhost:8090/settings \
--header 'Authorization: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2NzY4OTM3ODUsInVzZXJuYW1lIjoiYWRtaW4ifQ.dh-5OPn_njxoGhpaBeys8ncCnvEPY5UCEx2JZNl7xbo' \
--header 'Content-Type: application/json'
[
{
"key": "new-setting",
"value": "value for the new setting",
"ttl": 956,
"created_at": "2023-02-17T15:01:07.332995Z",
"updated_at": "2023-02-17T15:01:07.332995Z"
}
]
- Arman Jafarnezhad