| id | samples-rust-mongodb | |||||||
|---|---|---|---|---|---|---|---|---|
| title | Rust + MongoDB | |||||||
| sidebar_label | Rust + MongoDB | |||||||
| description | This sample app demonstrates how to use Rust with MongoDB and Keploy to automatically record and replay API test cases. | |||||||
| tags |
|
|||||||
| keyword |
|
import EnterpriseInstallReminder from '@site/src/components/EnterpriseInstallReminder'; import SectionDivider from '@site/src/components/SectionDivider'; import ProductTier from '@site/src/components/ProductTier';
A simple Notes REST API built with Rust and MongoDB, showcasing Keploy’s record & replay capabilities without writing manual test cases.
git clone https://github.com/Gagan202005/Keploy-Rust-Mongodb-QuickStart.git
cd Keploy-Rust-Mongodb-QuickStartRust is required to build and run the application.
Install Rust using rustup:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source "$HOME/.cargo/env"Verify installation:
rustc --version
cargo --versionStart MongoDB and Mongo Express using Docker Compose:
docker compose up -d mongo mongo-expressBuild & Run the Application 🛠️
docker compose up -d --build appVerify the application:
curl http://localhost:8000/Expected response:
Rust + MongoDB + Keploy Quickstart is running!Start recording with Keploy:
keploy record -c "docker compose up --build app" --container-name keploy-rust-appNow make some API calls (via curl, Postman, or Hoppscotch).
1️⃣ Create a Note
curl -X POST http://localhost:8000/notes \
-H "Content-Type: application/json" \
-d '{"text":"hello keploy"}'Response:
{
"text": "hello keploy"
}2️⃣ Fetch All Notes
curl http://localhost:8000/notesResponse:
{
"text": "hello keploy"
}We will get output something like this:
Keploy automatically records:
-
HTTP test cases
-
MongoDB mocks
Recorded data is stored at:
keploy/test-set-0/tests
keploy/test-set-0/mocksReplay the recorded test cases:
keploy test -c "docker compose up --build app" --delay 10 --container-name keploy-rust-appWe will get output something like this:
The --delay flag allows the application time to start before replay begins.
# Running Locally on Linux / WSL 🐧 {#running-app-locally} A simple Notes REST API built with Rust and MongoDB, showcasing Keploy’s record & replay capabilities without writing manual test cases.In local mode:
-
MongoDB runs in Docker
-
Rust application runs using cargo run
git clone https://github.com/Gagan202005/Keploy-Rust-Mongodb-QuickStart.git
cd Keploy-Rust-Mongodb-QuickStartRust is required to build and run the application locally.
Install Rust using rustup:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source "$HOME/.cargo/env"Verify installation:
rustc --version
cargo --versionStart MongoDB
docker compose up -d mongo mongo-expressRun the Application
cargo runYou should see:
Server running at http://localhost:8000Start recording:
keploy record -c "cargo run"Now make some API calls (via curl, Postman, or Hoppscotch).
1️⃣ Create a Note
curl -X POST http://localhost:8000/notes \
-H "Content-Type: application/json" \
-d '{"text":"hello keploy"}'Response:
{
"text": "hello keploy"
}2️⃣ Fetch All Notes
curl http://localhost:8000/notesResponse:
{
"text": "hello keploy"
}We will get output something like this:
Stop recording:
Ctrl + C
keploy test -c "cargo run" --delay 10We will get output something like this:
You’ve successfully:
-
Built a Rust + MongoDB REST API
-
Recorded real API traffic using Keploy
-
Replayed deterministic tests without hitting the database
Feel free to explore further by modifying:
-
test-x.yml -
mocks.yml
Happy Testing with Keploy 🐰✨



