A barebones Rocket API with JWT authentication and database integration.
The database integration can be switched between sqlite and postgres with a simple feature flag.
- Rust version 1.52 or newer.
- Diesel CLI with
postgresorsqlitefeatures. - A running PostgreSQL or Sqlite backend.
A .env.{db} at the root directory exposes environment both used by dieseland the project itself.
Rename it to .env then set all the environment variables before running the following commands :
source .envRun the following command to fulfill the requirements :
# Install Rust and cargo alongside rustup
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# Install ORM and query builder
cargo install diesel_cli --no-default-features --features "postgres sqlite"
# Run migrations
diesel setup
diesel migration runThen build the project with default database (sqlite):
cargo build --releaseor build with postgresql database:
$ cargo build --release --no-default-features --features postgres# Build the create-user binary
cargo build --release --features create-user-binary
# Execute the binary to create the first admin user
../target/release/create-userYou can use the feature flag to switch between database use:
- sqlite (default)
- postgres
To build the create-user binary
- create-user-binary
Any time you want to perform a database switch, you have to:
- Install and run the desired database on your machine if is not already the case
- Run migrations
- Build the project with the respective feature flag.
To print the project usage, an option -h is available.
- Get Swagger docs
GET /docs- Create a new user
POST /users
Authorization: Bearer <token>
{
"username": "string",
"password": "string",
"email": "string",
"is_admin": boolean
}- Authenticate
POST /auth
{
"username": "string",
"password": "string"
}- Get a list of users
GET /users
Authorization: Bearer <token>- Delete an existing user
DELETE /users/<username>
Authorization: Bearer <token>License: MIT