Simple http chat with custom JWT-based authentication and authorization, following clean architecture principles.
Create new user
{
"username": "mpeanuts",
"password": "1234"
}
curl -v -H "Content-Type: application/json" \
-X POST \
-d '{"username":"some","password":"1234"}' \
'localhost:1234/sign-up'
Request to get JWT Token based on user credentials
{
"username": "mpeanuts",
"password": "1234"
}
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2Njg5NTM2MDgsIlVzZXIiOnsiSUQiOjEsIlVzZXJuYW1lIjoic29tZSIsIlBhc3N3b3JkIjoiNWYwMmE0MDVhYzkwNDAzOGVhYjk5NDNkYzA0YjgxYWJlYWE2MThkMyJ9fQ.39hHxlPbS08KeQEAGH78rcJcx5zTRRGU2_ScpFMv5jo"
}
curl -v -H "Content-Type: application/json" \
-X POST \
-d '{"username":"some","password":"1234"}' \
'localhost:1234/sign-in'
Send message
To global chat:
{
"recipient": "",
"text": "Hi everybody"
}
Private message:
{
"recipient": "cgoth",
"text": "Hello, cgoth"
}
curl -v -H "Content-Type: application/json" \
-H "Authorization: Bearer <token>" \
-X POST \
-d '{"recipient":"some", "text":"hey you"}' \
'localhost:1234/api/send'
Get private messages sent to you
[
{
"Author": "cgoth",
"Text":"Hi there"
}
]
curl -v -H "Content-Type: application/json"\
-H "Authorization: Bearer <token>" -X GET\
'localhost:1234/api/read/private'
Get messages from the global chat
[
{
"Author": "cgoth",
"Text":"Hi there"
},
{
"Author": "user123",
"Text":"How are you?"
}
]
curl -v -H "Content-Type: application/json"\
-H "Authorization: Bearer <token>" -X GET\
'localhost:1234/api/read/global'