This repository is a template for building APIs in Rust with Rocket.
- Rocket
- Diesel
- Sqlite
Implemented:
- Two models : User and Message
- Routes to create, get, update, delete them
- Routes to catch 404 and serve statics
- Integration tests
- Sqlite connection pool
- Authentication by JWT
- Websocket to listen for the creation of new messages
- Worker to handle the generation of answers to messages
With docker:
docker-compose up -d --build
Without:
ROCKET_DATABASES='{rocket_template_db={url="db.sqlite"}}' cargo run
JWT_SECRET='foo' cargo test
.
├── Cargo.lock
├── Cargo.toml
├── Dockerfile
├── README.md
├── diesel.toml
├── docker-compose.yml
├── src
│ ├── bin
│ │ └── main.rs
│ ├── db
│ │ ├── common.rs
│ │ ├── message.rs
│ │ └── user.rs
│ ├── lib.rs
│ ├── logic
│ │ ├── home.rs
│ │ ├── message.rs
│ │ └── user.rs
│ ├── migrations
│ │ ├── 2024-06-15-081703_create_tables
│ │ │ ├── down.sql
│ │ │ └── up.sql
│ │ └── 2024-06-16-172322_add_user_name_and_password_in_users
│ │ ├── down.sql
│ │ └── up.sql
│ ├── models
│ │ ├── message.rs
│ │ └── user.rs
│ ├── routes
│ │ ├── home.rs
│ │ ├── message.rs
│ │ ├── message_channel.rs
│ │ └── user.rs
│ ├── schema.rs
│ ├── static
│ │ └── favicon.ico
│ ├── structs
│ │ ├── app_state.rs
│ │ ├── jwt.rs
│ │ ├── request.rs
│ │ ├── response.rs
│ │ ├── task.rs
│ │ └── worker_queue.rs
│ └── utils
│ ├── common.rs
│ ├── jwt.rs
│ └── worker.rs
└── tests
├── mod.rs
├── routes
│ ├── home.rs
│ ├── message.rs
│ └── user.rs
└── utils
└── test_context.rs
I wrote these two articles on Medium about this projet:
Please open an issue for support.
Please contribute using Github Flow. Create a branch, add commits, and open a pull request.