Skip to content

Actix API with web socket integration, Auth middleware and DB migrations

Notifications You must be signed in to change notification settings

NoctDevT/Rust-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A rust based API learning project using Actix Web, Diesel ( for Postgresql management ) DB migrations and JWT authentication.

To start

Use run Docker Compose up --build

.env setup for rust:

  SECRET_KEY=r2wh9HNLpaBwKBsVksLJ8NwD+T18Mju44bMHvQ62DU4=
  JWT_EXPIRATION=3600
  # DATABASE_URL=postgres://my_user:my_password@db:5432/my_database
  DATABASE_URL=postgres://my_user:my_password@localhost:5432/my_database

Database Schema This project utilizes Diesel as an ORM to interact with our PostgreSQL database. The schema is automatically generated by the Diesel CLI and includes definitions for Users and Surveys. Currently incomplete due to priortisation on using the project to develop understanding of how Actix Web works.

Hosted on Localhost:8000

Routes

POST ROUTES: /login -> JSON Token, 401 or 401 JSON Body structure

{
        "username": "testuser2",
        "password": "password123",
        "name": "John Doe",
}

/register -> 400 or 401 JSON Body structure

{
        "username": "testuser2",
        "password": "password123",
        "name": "John Doe",
        "description": "A software developer"
}

Web Socket Connection

/ws/survey

When connected, enter JWT token from /login route.

To authenticate:

{
  "type": "Authenticate",
  "data": {
    "token": "JWT TOKEN"
  }
}

To request a survey from the DB:

  "type": "RequestSurvey",
  "data": {
    "survey_id": "550e8400-e29b-41d4-a716-446655440000"
  }
}

To submit a survey with all questions attached:

    "type": "SubmitResponses",
    "data": {
        "survey_id": "550e8400-e29b-41d4-a716-446655440000",
        "responses": [
            {
                "question_id": "b2c3d4e5-e89b-12d3-a456-426614174003",
                "answer": "Very not satisfied"
            }
        ]
    }
}```





About

Actix API with web socket integration, Auth middleware and DB migrations

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published