Skip to content

takecore/actix-web3-rest-api-boilerplate

Repository files navigation

Actix-web3 REST API boilerplate

Setup and run server

# Need to install diesel_cli on your system to run migration.
$ cargo install diesel_cli --no-default-features --features "postgres"
$ echo DATABASE_URL=postgres://username:password@yourhost/good_db_name > .env
$ diesel setup
$ make run

# If installed cargo-watch, This can be auto recompile.
$ make watch

Structure

├── Cargo.lock
├── Cargo.toml
├── diesel.toml
├── Makefile
├── migrations
│   ├── 00000000000000_diesel_initial_setup
│   │   ├── down.sql
│   │   └── up.sql
│   └── ...
├── README.md
├── src
│   ├── apps
│   │   ├── companies
│   │   │   ├── models.rs
│   │   │   ├── mod.rs
│   │   │   └── views.rs
│   │   ├── mod.rs
│   │   ├── users
│   │   │   ├── models.rs
│   │   │   ├── mod.rs
│   │   │   └── views.rs
│   │   └── ... # create other resouce
│   ├── bin
│   │   └── main.rs
│   ├── db.rs
│   ├── error.rs
│   ├── lib.rs
│   ├── schema.rs
│   └── server.rs
└── tests
    └── apps
        └── health_check.rs

Other

create migration files

$ diesel migration generate create_xxx

run migraiton

$ make migration

rollback and run migraiton

$ make migration-redo

reset db

$ make reset-db