An example API using Rust and Postgres based on a combination of a few different web tutorials and framework documentation.
- The database framework is Diesel.
- The API framework is Rocket.
- File watcher reloading using cargo-watch.
- Database admin using Adminer.
- Docker
This example does not require Rust or Postgres to be installed locally.
The cargo watch command that runs when the container starts works best on Linux (not Windows) if you want it to detect file changes.
If you are using WSL, clone this repo on the WSL drive rather than a mounted drive to get automatic reloading on file changes.
docker compose up- Sit back and watch it compile ☕
When the application runs it will:
- Create the database
- Run the database migrations to create a users table
- Seed the users table with some random example data.
Try accessing a GET endpoint http://localhost:8000/users or http://localhost:8000/users/{userId} or http://localhost:8000/version.
NB: The API endpoints are configured so the content-type on the request must be set to application/json.
View the database using Adminer on http://localhost:8080 and enter the following connection details:
- System: PostgreSQL
- Server: pg_db
- Username: postgres
- Password: sheldon