Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lz1998/axum-book-management
CRUD system of book-management with ORM and JWT for educational purposes.
https://github.com/lz1998/axum-book-management
axum crud demo example http http-server jwt mysql orm rust sea-orm tutorial
Last synced: about 1 month ago
JSON representation
CRUD system of book-management with ORM and JWT for educational purposes.
- Host: GitHub
- URL: https://github.com/lz1998/axum-book-management
- Owner: lz1998
- License: mit
- Created: 2021-12-29T18:01:18.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-12-01T12:21:20.000Z (about 1 year ago)
- Last Synced: 2023-12-01T13:59:26.145Z (about 1 year ago)
- Topics: axum, crud, demo, example, http, http-server, jwt, mysql, orm, rust, sea-orm, tutorial
- Language: Rust
- Homepage:
- Size: 17.6 KB
- Stars: 47
- Watchers: 2
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Book management
English | [中文](README_cn.md)
## 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 `
- /book/create
- /book/search
- /book/update
- /book/delete## Practice
### Use Redis as cache
1. Add [redis](https://github.com/redis-rs/redis-rs) 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.
2. Add `redis::RedisError` in src/error.rs
```rust
#[error("redis_error: {0}")]
Redis(#[from] redis::RedisError),
```
> With `#[from]`, [thiserror](https://github.com/dtolnay/thiserror) will generate `impl From for CustomError` automatically, and you can return error with `?` or `.map_err(Into::into)?` when the return type is `CustomResult`.
> Without `#[from]`, you need to convert error by yourself `.map_err(|e| CustomError::Redis(e))` or `.map_err(CustomError::Redis)`
3. Read code in [redis/examples](https://github.com/redis-rs/redis-rs/blob/main/redis/examples/async-await.rs).
4. Write your cache code.### Global 404 handler
1. Add [Global-404-handler](https://github.com/tokio-rs/axum/tree/main/examples/global-404-handler) in `src/bin/server.rs`.