English | 中文
- Rust
- MySQL 5.7
- Execute
init.sqlto create tables. - Set environment variable
DATABASE_URLandJWT_SECRETin.env. - Execute
run.sh.
- /user/register
- /user/login
JWT should be provided in header.
Authorization: Bearer <JWT>
- /book/create
- /book/search
- /book/update
- /book/delete
- Add redis with feature
tokio-compto Cargo.toml
asyncis necessary, because if you don't useasync, the system thread will block when the command is executing, and it will not handle other tasks.
- Add
redis::RedisErrorin src/error.rs
#[error("redis_error: {0}")]
Redis(#[from] redis::RedisError),With
#[from], thiserror will generateimpl From<redis::RedisError> for CustomErrorautomatically, and you can return error with?or.map_err(Into::into)?when the return type isCustomResult<T>.
Without#[from], you need to convert error by yourself.map_err(|e| CustomError::Redis(e))or.map_err(CustomError::Redis)
- Read code in redis/examples.
- Write your cache code.
- Add Global-404-handler in
src/bin/server.rs.