diff --git a/src/components/QuickStartFilter.js b/src/components/QuickStartFilter.js index 8e86dfe54..ac6ed7846 100644 --- a/src/components/QuickStartFilter.js +++ b/src/components/QuickStartFilter.js @@ -3,7 +3,7 @@ import quickstarts from "./QuickStartList"; import Link from "@docusaurus/Link"; import {FaGolang} from "react-icons/fa6"; import {FaJava, FaLaptopCode, FaDocker, FaPython, FaCheck, FaArrowRight, FaArrowLeft} from "react-icons/fa"; -import {TbBrandCSharp} from "react-icons/tb"; +import {TbBrandCSharp, TbBrandRust} from "react-icons/tb"; import {IoLogoJavascript} from "react-icons/io5"; import {useColorMode} from "@docusaurus/theme-common"; @@ -28,6 +28,8 @@ export default function QuickstartFilter({defaultLanguage = null}) { {name: "Java", icon: , color: "#007396"}, {name: "JS/TS", icon: , color: "#F7DF1E"}, {name: "C#", icon: , color: "#512BD4"}, + {name: "Rust", icon: , color: "#DEA584"}, + ]; const servers = [ diff --git a/src/components/QuickStartList.js b/src/components/QuickStartList.js index 17f9e6e03..75e3ab61e 100644 --- a/src/components/QuickStartList.js +++ b/src/components/QuickStartList.js @@ -395,6 +395,26 @@ const quickstarts = [ "A sample app to demonstrate Keploy integration capabilities using TypeScript and Nhost.", link: "/docs/quickstart/samples-typescript/#running-the-app-using-docker", }, + + // rust list +{ + title: "Rust + MongoDB", + language: "Rust", + server: "Local", + description: + "A sample Rust CRUD notes application using MongoDB to demonstrate how Keploy records API calls and database interactions automatically and replays them without manual test writing.", + link: "/docs/quickstart/samples-rust-mongodb/#running-app-locally", +}, +{ + title: "Rust + MongoDB", + language: "Rust", + server: "Docker", + description: + "A sample Rust CRUD notes application using MongoDB to demonstrate Keploy record & replay workflows using Docker Compose.", + link: "/docs/quickstart/samples-rust-mongodb/#using-docker-compose", +}, + + ]; export default quickstarts; diff --git a/src/components/SidebarCategoryIcon.js b/src/components/SidebarCategoryIcon.js index 6f86cd34b..934c41513 100644 --- a/src/components/SidebarCategoryIcon.js +++ b/src/components/SidebarCategoryIcon.js @@ -21,7 +21,7 @@ import { import { SiKubernetes, SiDocker, - SiGithubactions + SiGithubactions, } from 'react-icons/si'; /** @@ -48,12 +48,13 @@ const categoryIcons = { 'security': FaShieldAlt, 'operation': FaTools, - // Language/Framework categories + // Language / Framework categories 'java': FaCode, 'golang': FaCode, 'python': FaCode, 'javascript': FaCode, 'typescript': FaCode, + 'rust': FaCode, // Infrastructure 'docker': SiDocker, @@ -79,7 +80,11 @@ export function getCategoryIcon(categoryLabel) { return categoryIcons[key] || null; } -export default function SidebarCategoryIcon({ category, size = 16, className = '' }) { +export default function SidebarCategoryIcon({ + category, + size = 16, + className = '', +}) { const Icon = getCategoryIcon(category); if (!Icon) return null; @@ -113,4 +118,3 @@ export default function SidebarCategoryIcon({ category, size = 16, className = ' // Export icon mapping for use in sidebar configuration export { categoryIcons }; - diff --git a/static/img/rust-mongodb-docker-record.png b/static/img/rust-mongodb-docker-record.png new file mode 100644 index 000000000..394cdc653 Binary files /dev/null and b/static/img/rust-mongodb-docker-record.png differ diff --git a/static/img/rust-mongodb-docker-replay.png b/static/img/rust-mongodb-docker-replay.png new file mode 100644 index 000000000..88dfc5118 Binary files /dev/null and b/static/img/rust-mongodb-docker-replay.png differ diff --git a/static/img/rust-mongodb-local-record.png b/static/img/rust-mongodb-local-record.png new file mode 100644 index 000000000..26e53298a Binary files /dev/null and b/static/img/rust-mongodb-local-record.png differ diff --git a/static/img/rust-mongodb-local-replay.png b/static/img/rust-mongodb-local-replay.png new file mode 100644 index 000000000..0260b6304 Binary files /dev/null and b/static/img/rust-mongodb-local-replay.png differ diff --git a/versioned_docs/version-4.0.0/quickstart/samples-rust-mongodb.md b/versioned_docs/version-4.0.0/quickstart/samples-rust-mongodb.md new file mode 100644 index 000000000..52430ead1 --- /dev/null +++ b/versioned_docs/version-4.0.0/quickstart/samples-rust-mongodb.md @@ -0,0 +1,282 @@ +--- +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: + - rust + - quickstart + - samples + - examples + - tutorial + - mongodb + - keploy +keyword: + - Rust + - MongoDB + - Keploy + - API Test Generator + - Auto Testcase Generation +--- + +import EnterpriseInstallReminder from '@site/src/components/EnterpriseInstallReminder'; +import SectionDivider from '@site/src/components/SectionDivider'; +import ProductTier from '@site/src/components/ProductTier'; + +# Using Docker Compose 🐳 {#using-docker-compose} + + + +A simple **Notes REST API** built with **Rust** and **MongoDB**, showcasing **Keploy’s record & replay** capabilities without writing manual test cases. + + + +--- + +### Clone the Sample Application + +```bash +git clone https://github.com/Gagan202005/Keploy-Rust-Mongodb-QuickStart.git +cd Keploy-Rust-Mongodb-QuickStart +``` +### Rust (Cargo) + +Rust is required to build and run the application. + +Install Rust using **rustup**: +```bash +curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh +source "$HOME/.cargo/env" +``` +**Verify installation**: +```bash +rustc --version +cargo --version +``` + +### Lights, Camera, Record! + + +Start MongoDB and Mongo Express using Docker Compose: + +```bash +docker compose up -d mongo mongo-express +``` + +Build & Run the Application 🛠️ + +```bash +docker compose up -d --build app +``` + +Verify the application: + +```bash +curl http://localhost:8000/ +``` + +Expected response: +```bash +Rust + MongoDB + Keploy Quickstart is running! +``` +### Capture Test Cases + +Start recording with Keploy: + +```bash +keploy record -c "docker compose up --build app" --container-name keploy-rust-app +``` + +Now make some API calls (via curl, Postman, or Hoppscotch). + +1️⃣ Create a Note + +```bash +curl -X POST http://localhost:8000/notes \ + -H "Content-Type: application/json" \ + -d '{"text":"hello keploy"}' + ``` + +Response: + +```bash +{ + "text": "hello keploy" +} +``` + +2️⃣ Fetch All Notes + +```bash +curl http://localhost:8000/notes +``` + +Response: + +```bash +{ + "text": "hello keploy" +} +``` +We will get output something like this: + +![Keploy Record Mode](../../../static/img/rust-mongodb-docker-record.png) + +Keploy automatically records: + +- HTTP test cases + +- MongoDB mocks + +Recorded data is stored at: + +```bash +keploy/test-set-0/tests +keploy/test-set-0/mocks +``` + +### Run Tests ▶️ + +Replay the recorded test cases: + +```bash +keploy test -c "docker compose up --build app" --delay 10 --container-name keploy-rust-app +``` +We will get output something like this: + +![Keploy Replay Mode](../../../static/img/rust-mongodb-docker-replay.png) + +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 + +### Clone the Sample Application + +```bash +git clone https://github.com/Gagan202005/Keploy-Rust-Mongodb-QuickStart.git +cd Keploy-Rust-Mongodb-QuickStart +``` +### Rust (Cargo) + +Rust is required to build and run the application locally. + +Install Rust using **rustup**: +```bash +curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh +source "$HOME/.cargo/env" +``` + +**Verify installation**: +```bash +rustc --version +cargo --version +``` +### Lights, Camera, Record! + +**Start MongoDB** + +```bash +docker compose up -d mongo mongo-express +``` + +**Run the Application** + +```bash +cargo run +``` + +You should see: +```bash +Server running at http://localhost:8000 +``` +### Record Tests (Local) + +Start recording: + +```bash +keploy record -c "cargo run" +``` + +Now make some API calls (via curl, Postman, or Hoppscotch). + +1️⃣ Create a Note + +```bash +curl -X POST http://localhost:8000/notes \ + -H "Content-Type: application/json" \ + -d '{"text":"hello keploy"}' + ``` + +Response: + +```bash +{ + "text": "hello keploy" +} +``` + +2️⃣ Fetch All Notes + +```bash +curl http://localhost:8000/notes +``` + +Response: + +```bash +{ + "text": "hello keploy" +} +``` +We will get output something like this: + +![Keploy Record Mode](../../../static/img/rust-mongodb-local-record.png) + + +Stop recording: + +- `Ctrl + C` + +### Replay Tests (Local) + +```bash +keploy test -c "cargo run" --delay 10 +``` +We will get output something like this: + +![Keploy Replay Mode](../../../static/img/rust-mongodb-local-replay.png) + + + +# Wrapping It Up + +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 🐰✨ + + \ No newline at end of file diff --git a/versioned_sidebars/version-4.0.0-sidebars.json b/versioned_sidebars/version-4.0.0-sidebars.json index 6399724df..329f30c56 100644 --- a/versioned_sidebars/version-4.0.0-sidebars.json +++ b/versioned_sidebars/version-4.0.0-sidebars.json @@ -118,7 +118,24 @@ "items": [ "quickstart/samples-csharp" ] - } + }, + { + "type": "category", + "label": "Rust", + "link": { + "type": "doc", + "id": "quickstart/rust-filter" + }, + "collapsible": true, + "collapsed": true, + "items": [ + "quickstart/samples-rust-mongodb" + ] +} + + + + ] }, { @@ -211,4 +228,4 @@ ] } ] -} \ No newline at end of file +}