Skip to content
/ axum-book-management Public template

CRUD system of book-management with ORM and JWT for educational purposes.

License

Notifications You must be signed in to change notification settings

lz1998/axum-book-management

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Book management

English | 中文

Required

  • Rust
  • MySQL 5.7

Usage

  1. Execute init.sql to create tables.
  2. Set environment variable DATABASE_URL and JWT_SECRET in .env.
  3. Execute run.sh.

API

user

  • /user/register
  • /user/login

book

JWT should be provided in header. Authorization: Bearer <JWT>

  • /book/create
  • /book/search
  • /book/update
  • /book/delete

Practice

Use Redis as cache

  1. Add redis with feature tokio-comp to Cargo.toml

async is necessary, because if you don't use async, the system thread will block when the command is executing, and it will not handle other tasks.

  1. Add redis::RedisError in src/error.rs
    #[error("redis_error: {0}")]
    Redis(#[from] redis::RedisError),

With #[from], thiserror will generate impl From<redis::RedisError> for CustomError automatically, and you can return error with ? or .map_err(Into::into)? when the return type is CustomResult<T>.
Without #[from], you need to convert error by yourself .map_err(|e| CustomError::Redis(e)) or .map_err(CustomError::Redis)

  1. Read code in redis/examples.
  2. Write your cache code.

Global 404 handler

  1. Add Global-404-handler in src/bin/server.rs.

Releases

No releases published

Packages

No packages published