Build Restful CRUD API for a managing heroes within our Database using Rocket and Diesel.
-
Rust and Cargo - 1.26.0 (nightly)
-
Diesel CLI - 1.1.0
-
Mysql - 5.x.x
1. Clone the application
git clone https://github.com/sean3z/rocket-diesel-rest-api-example.git
2. Create DATABASE_URL environment variable
export DATABASE_URL=mysql://user:pass@localhost/heroes
3. Run Database migration
diesel migration run
4. Build and run the app using cargo
cargo build --release && cd target/release/
sudo ROCKET_ENV=prod ./hero-api
The app will start running at http://localhost:80.
Alternatively, you can run the app in development mode -
cargo run
The app defines following CRUD APIs.
GET /heroes
POST /hero
PUT /hero/{heroId}
DELETE /hero/{heroId}
You can test them using postman or any other rest client.
You can find the tutorial for this application on my blog -