This Rust API, built with Actix, features both public and protected routes. Authentication is handled using JSON Web Tokens (JWT), which are securely stored in Redis.
- Secure authentication with JWT tokens.
- Public and protected API routes.
- Modular project structure for maintainability.
- Built with Actix-web for high performance.
./rust-actix-jwt-redis
│── src/
│ ├── handlers/ # Request handlers
│ ├── middlewares/ # Middleware for authentication
│ ├── routes/ # Route definitions
│ ├── main.rs # Application entry point
│── Cargo.toml # Project dependencies and metadata
Ensure you have the following installed:
git clone https://github.com/hmanzoni/rust-actix-jwt-redis.git
cd rust-actix-jwt-redis
cargo build
Start the server using:
cargo run
The server will start on http://127.0.0.1:8080/
GET /
- Open route accessible without authentication.GET /hey
- Open route accessible without authentication.POST /auth/login
- Open route accessible without authentication.
POST /echo
- Access restricted to authenticated users.
To access protected routes, obtain a JWT token via login. Example:
curl -X POST http://127.0.0.1:8080/auth/login -d '{"username": "test", "password": "test_password"}' -H "Content-Type: application/json"
The response will include a JWT token:
{
"token": "your_generated_jwt_token"
}
Use the token in the Authorization header:
curl -X POST http://127.0.0.1:8080/echo -d 'Test messagge' -H "Authorization: Bearer your_generated_jwt_token"
This project is licensed under the MIT License. See the LICENSE
file for details.
Feel free to open issues or submit pull requests to improve the project.