Skip to content

biluohc/actixweb-sqlx-jwt

Repository files navigation

actixweb-sqlx-jwt

A jwt template project of actix-web and sqlx

sqlx-cli

cargo install sqlx-cli --git https://github.com/launchbadge/sqlx

Usage

  1. Choose a database(mysql, postgres, sqlite).
  2. Sets the default feature as the database name on Cargo.toml(current is mysql).
  3. Configure the databse you can see sql/user.up.$database.sql.
  4. Run cargo run -- -v after update .env and template.json.
  5. Test current api:
curl -v --data '{"name": "Bob", "email": "[email protected]", "password": "Bobpass"}' -H "Content-Type: application/json" -X POST localhost:8080/user/register

curl -v --data '{"name": "Bob", "email": "[email protected]", "password": "Bobpass"}' -H "Content-Type: application/json" -X POST localhost:8080/user/login

curl -H 'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJCb2IiLCJleHAiOjE1OTEyNDYwOTR9.O1dbYu3tqiIi6I8OUlixLuj9dp-1tLl4mjmXZ0ve6uo' localhost:8080/user/userInfo

curl -v -X DELETE -H 'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJCb2IiLCJleHAiOjE1OTEyNDYwOTR9.O1dbYu3tqiIi6I8OUlixLuj9dp-1tLl4mjmXZ0ve6uo' localhost:8080/user/delete/Bob 

curl 'localhost:8080/user/userInfo?access_token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJCb2IiLCJleHAiOjE1OTEyNTYxNDd9.zJKlZOozYfq-xMXO89kjUyme6SA8_eziacqt5gvXj2U'
  1. Modify the code and write your own code, enjoy.

Notice

  1. The sqlx query macros needs to be connected to the database represented by DATABASE_URL in .env, or you can consider using the unchecked version instead.

Redis: No Redis does not affect the program running now

  1. Use docker to start a Redis quickly
docker run --name redis-6379 --network host -d redis redis-server --port 6379 --bind 127.0.0.1 --appendonly  no  # --requirepass pw

# pip3 install iredis

# iredis/redis-cli -p 6379 # -a pw
  1. The Redis client crates, current is mobc.
    1. redis-rs: The most used Redis client.
    2. mobc: An asynchronous connection pool.
    3. deadpool: An asynchronous connection pool.
    4. actix-redis: Redis integration for actix framework base on redis-async-rs.
    5. bb8: An asynchronous connection pool provides the same configuration options as r2d2.
    6. r2d2: A synchronized connection pool, not recommended.
    7. redis-async-rs: Another Redis client.

References

  1. actix-web: https://github.com/actix/actix-web
  2. sqlx: https://github.com/launchbadge/sqlx
  3. actix documentation: https://actix.rs/docs/
  4. actix-web-jwt with mongodb: https://github.com/emreyalvac/actix-web-jwt
  5. actix-examples: https://github.com/actix/examples
  6. an instance: https://github.com/biluohc/KeepStats
  7. ormx: https://github.com/NyxCode/ormx
  8. sea-orm: https://github.com/SeaQL/sea-orm
  9. sea-query: https://github.com/SeaQL/sea-query
  10. Prisma Client Rust: https://github.com/Brendonovich/prisma-client-rust
  11. validator: https://docs.rs/validator
  12. axum: https://github.com/tokio-rs/axum

About

A jwt template project of actix-web and sqlx

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published