A template for creating REST API's using axum & sqlx.
Built with:
This template uses Docker for deployment so you don't need to install anything other than below listed packages on the production system.
You can click "Use this template" or just fork and start using it.
You can clone this repository and start using it.
Check src/config.rs for necessary environemnt variables.
- Change package name in Cargo.toml
- Update import names in src/main.rs to reflect the new package name from above
- Change container names in docker-compose.yml
-
Make sure you set DATABASE_URL in your environment variables.
I recommend using direnv + .env
-
Create database
sqlx database create
-
Create a migration
Note: You just need to do this step so it creates a "migrations" directory, you don't necessarily need to add anything in the migration files yet.
sqlx migrate add -r init
-
Run the app
cargo run
-
Update the environment file:
Copy the .env.sample file to .env and then modify the contents for production
-
Run the app:
docker-compose up -d
To add HTTPS Encryption to your server, it is recommended to use a reverse proxy like caddy/nginx instead of handling the HTTPS traffic directly.