Skip to content

hmanzoni/rust-actix-jwt-redis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🦀 Rust API with Actix, JWT and Redis

Overview

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.

🚀 Features

  • Secure authentication with JWT tokens.
  • Public and protected API routes.
  • Modular project structure for maintainability.
  • Built with Actix-web for high performance.

📁 Project Structure

./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

🛠️ Installation and Setup

Prerequisites

Ensure you have the following installed:

Clone the repository

git clone https://github.com/hmanzoni/rust-actix-jwt-redis.git
cd rust-actix-jwt-redis

Install dependencies

cargo build

Running the Project

Start the server using:

cargo run

The server will start on http://127.0.0.1:8080/

API Endpoints

Public Routes

  • GET / - Open route accessible without authentication.
  • GET /hey - Open route accessible without authentication.
  • POST /auth/login - Open route accessible without authentication.

Protected Routes (Require JWT Token)

  • POST /echo - Access restricted to authenticated users.

Authentication

Generating a JWT Token

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"
}

Accessing Protected Routes

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"

📜 License

This project is licensed under the MIT License. See the LICENSE file for details.

Contributing

Feel free to open issues or submit pull requests to improve the project.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages