Restfull API allowing users to register and login. The authentication is realized with JWT and bcrypt for securely store passwords. The API allows for creating tasks, updating, fetching and deleting tasks stored in the database.
API used to help user stay organized by storing tasks. It includes
- JWT-based authentication
- Task creation, updating, fetching and deleting
- Database integration with postgres
Follow the steps to build and run the server locally.
- Rust(1.86.0)
- PostgresSQL
- Git
- Clone the repository.
git clone https://github.com/Simone-Samardzhiev/task-server-rust
cd task-server-rust- Add .env file
DATABASE_URL=postgres://postgres:postgres@localhost:5432/postgres
SERVER_ADDR=127.0.0.1:8080
JWT_SECRET=secret- Build and run
cargo build --release
cd tatget
cd release
./serverThe endpoint allows users to register.
The body of the request should contain the user credentials
{
"email": "exmaple@email.com",
"username": "Someone",
"password": "Password_123"
}The user payload is validated before being accepted. If the email or the username is already in use the API will return an error. Also, there are more requirements for the user credentials:
- The email should be properly formated with valid local and domain part.
- The username should be less than 8 letters
- The password should be secure:
- At least one capital letter
- At least one small letter
- At least one number.
- At least one special character(! " # $ % & ' ( ) * + , - . : ; < = > ? [ \ ] ^ _ `{ | } ~)
The endpoint allows user to receive JWT refresh and access token.
The body of the request should contain user credentials
{
"email": "exmaple@email.com",
"username": "Someone",
"password": "Password_123"
}If the credential the server will return Status Code Unauthorized.
If not the response will be like:
{
"refresh_token": "token",
"access_token": "token"
}The endpoint allows user to send refresh to token, for a new refresh and access token.
Authorization: Bearer + refresh token
If the token is expired the server will return Status Code Unauthorized.
If not the response will be like:
{
"refresh_token": "token",
"access_token": "token"
}The endpoint allows user to get all their tasks.
Authorization: Bearer + refresh token
If the token is expired the server will return Status Code Unauthorized.
If not the response will be like:
[
{
"id": "ffafdd8a-20ba-452f-b5b4-37d98b091ba0",
"name": "Task name",
"description": "Task description",
"priority": "Low",
"date": "2025-03-15T16:03:30Z"
}
]The endpoint allows user to add a new task.
Authorization: Bearer + refresh token
The body should contain the task information
{
"name": "Name",
"description": "Description",
"priority": "Low",
"data": "2025-03-15T16:03:30Z"
}The task payload is also validated before storing it. None of the filed can be empty. Also, the priority will be checked by the database. You could easily adjust the priority by updating Priorities table
If the token is expired the server will return Status Code Unauthorized.
If not the response will be like:
{
"id": "ffafdd8a-20ba-452f-b5b4-37d98b091ba0",
"name": "Name",
"description": "Description",
"priority": "Vital",
"date": "2025-03-15T16:03:30Z"
}The endpoint allows user to update an existing token.
Authorization: Bearer + refresh token
The body should contain the token information
{
"id": "ffafdd8a-20ba-452f-b5b4-37d98b091ba0",
"name": "Task name",
"description": "Task description",
"type": "High",
"date": "2025-03-15T16:03:30Z"
}Note that updating task also validate the payload.
If the token is expired the server will return Status Code Unauthorized.
If the task is found the server will return Status Code OK
If the task is not found the server will return Status Code Not Found
The endpoint allows user to delete a task.
Authorization: Bearer + refresh token
id The id of the token
If the token is expired the server will return Status Code Unauthorized.
If the task is found the server will return Status Code OK
If the task is not found the server will return Status Code Not Found