Skip to content

A template for creating APIs in rust with axum & sqlx (postgres). Includes a pre-configured Docker setup for deployments.

License

Notifications You must be signed in to change notification settings

hellodhruvin/axum-sqlx-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Axum-sqlx Template

A template for creating REST API's using axum & sqlx.

Built with:

Requirements:

Development

Deployment

This template uses Docker for deployment so you don't need to install anything other than below listed packages on the production system.

How to use the template

For public repositories

You can click "Use this template" or just fork and start using it.

For private repositories

You can clone this repository and start using it.

Configuration

Check src/config.rs for necessary environemnt variables.

Rename your project

  1. Change package name in Cargo.toml
  2. Update import names in src/main.rs to reflect the new package name from above
  3. Change container names in docker-compose.yml

Running the application locally

  1. Make sure you set DATABASE_URL in your environment variables.

    I recommend using direnv + .env

  2. Create database

    sqlx database create
    
  3. 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
    
  4. Run the app

    cargo run
    

Deploy the app for production

  1. Update the environment file:

    Copy the .env.sample file to .env and then modify the contents for production

  2. Run the app:

    docker-compose up -d
    

Adding TLS Encryption (HTTPS)

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.

About

A template for creating APIs in rust with axum & sqlx (postgres). Includes a pre-configured Docker setup for deployments.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published