| id | rust-actix-postgres | |||||
|---|---|---|---|---|---|---|
| title | Application with Postgres | |||||
| sidebar_label | Actix + Postgres | |||||
| description | A sample Actix-web application to demonstrate Keploy integration capabilities using Rust and Postgres. | |||||
| tags |
|
|||||
| keyword |
|
import InstallReminder from '@site/src/components/InstallReminder';
This guide will walk you through setting up a simple Rust application using Actix-web and Postgres (via SQLx) and integrating it with Keploy for automated testing.
We will cover two methods:
- Docker Compose (Recommended)
- Local Binary
git clone https://github.com/keploy/samples-rust.git
cd samples-rust/rust-actix-postgresThis is the easiest way to get started as it sets up both the application and the Postgres database for you.
docker compose up -dThe application will be running at http://localhost:8080.
To record test cases, we use the keploy record command. This will start your application (via Docker) and proxy the traffic to record interactions.
keploy record -c "docker compose up" --container-name rust-appNow, generate some traffic using curl or Postman:
Create an Item:
curl -X POST http://localhost:8080/items \
-H "Content-Type: application/json" \
-d '{"name": "Keploy Guide", "description": "Writing tests made easy"}'Get Items:
curl http://localhost:8080/itemsStop the recording by pressing Ctrl+C. You should see a keploy/ directory created with your test cases.
Now, let's verify the recorded test cases.
keploy test -c "docker compose up" --container-name rust-app --delay 10Keploy will compare the current responses with the recorded ones.
If you prefer to run the Rust binary directly, follow these steps.
We'll use Docker to spin up the Postgres database only.
docker compose up db -dTo connect to the database, you need to set the connection string. You can either create a .env file or export the variable.
export DATABASE_URL=postgres://postgres:password@localhost:5432/keployNow, run the application with Keploy to record traffic.
keploy record -c "cargo run"Once the application matches Server running at http://0.0.0.0:8080, generate some traffic.
Create an Item:
curl -X POST http://localhost:8080/items \
-H "Content-Type: application/json" \
-d '{"name": "Keploy Guide", "description": "Writing tests made easy"}'Get Items:
curl http://localhost:8080/itemsStop the recording by pressing Ctrl+C.
Now, let's verify the recorded test cases.
keploy test -c "cargo run" --delay 10Keploy will run the tests and show the results in the terminal.
You have successfully:
- Set up a Rust Actix-web application.
- Recorded API interactions using Keploy.
- Replayed and validated the interactions.








