Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/components/QuickStartFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {FaJava, FaLaptopCode, FaDocker, FaPython, FaCheck, FaArrowRight, FaArrow
import {TbBrandCSharp} from "react-icons/tb";
import {IoLogoJavascript} from "react-icons/io5";
import {useColorMode} from "@docusaurus/theme-common";
import {SiPerl} from "react-icons/si";


export default function QuickstartFilter({defaultLanguage = null}) {
const {colorMode} = useColorMode();
Expand All @@ -28,6 +30,7 @@ export default function QuickstartFilter({defaultLanguage = null}) {
{name: "Java", icon: <FaJava size={24} />, color: "#007396"},
{name: "JS/TS", icon: <IoLogoJavascript size={24} />, color: "#F7DF1E"},
{name: "C#", icon: <TbBrandCSharp size={24} />, color: "#512BD4"},
{name: "Perl", icon: <SiPerl size={24} />, color: "#39457E"},
];

const servers = [
Expand Down
18 changes: 18 additions & 0 deletions src/components/QuickStartList.js
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,24 @@ const quickstarts = [
"A sample app to demonstrate Keploy integration capabilities using TypeScript and Nhost.",
link: "/docs/quickstart/samples-typescript/#running-the-app-using-docker",
},

// Perl List
{
title: "Perl + MongoDB",
language: "Perl",
server: "Local",
description:
"A sample URL Shortener app to demonstrate Keploy integration capabilities using Perl and MongoDB.",
link: "/docs/quickstart/perl-mongo/#running-app-locally-on-linuxwsl-",
},
{
title: "Perl + MongoDB",
language: "Perl",
server: "Docker",
description:
"A sample URL Shortener app to demonstrate Keploy integration capabilities using Perl and MongoDB.",
link: "/docs/quickstart/perl-mongo/#running-app-using-docker-compose-",
},
];

export default quickstarts;
Binary file added static/img/oss/perl-mongo-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/img/oss/perl-mongo-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
311 changes: 311 additions & 0 deletions versioned_docs/version-4.0.0/quickstart/perl-mongo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,311 @@
---
id: perl-mongo
title: Sample Perl-MongoDB URL Shortener App
sidebar_label: Perl + MongoDB
description: The following sample app showcases how to use the Perl framework and the Keploy Platform.

tags:
- perl
- quickstart
- samples
- examples
- tutorial
- perl-framework
- mongodb
keyword:
- Perl Framework
- MongoDB
- API Test generator
- Auto case generation
---

import Link from '@docusaurus/Link'
import InstallReminder from '@site/src/components/InstallReminder';
import SectionDivider from '@site/src/components/SectionDivider';

## How to run the sample application Using Docker Compose 🐳

🪄 In this guide, you will set up a Perl-based URL Shortener using MongoDB and learn how Keploy enables automated API testing through record and replay modes. 🎢

<InstallReminder />

### Get Started! 🎬

Clone the repository and move to relevant folder

```bash
git clone https://github.com/Akshat005Chaudhary/keploy-perl-mongodb-quickstart.git
cd keploy-perl-mongodb-quickstart
```

We will be using Docker compose to run the application as well as Mongo on Docker container.

### Lights, Camera, Record! 🎥

Fire up the application and mongoDB instance with Keploy. Keep an eye on the two key flags:
`-c`: Command to run the app (e.g., `docker compose up`).

`--container-name`: The container name in the `docker-compose.yml` for traffic interception.

```bash
keploy record -c "docker compose up" --container-name=perl-app
```

![alt text](/img/oss/perl-mongo-1.png)

🔥 Challenge time! Generate some test cases. How? Just **make some API calls**. Postman, Hoppscotch or even curl - take your pick!

### Let's generate the testcases.

Make API Calls using Postman or cURL command. Keploy with capture those calls to generate the test-suites containing testcases and data mocks.

**1. POST /shorten**

```bash
curl -X POST http://localhost:5000/shorten \
-H "Content-Type: application/json" \
-d '{"url":"https://keploy.io"}'
```

Here's a peek of what you get:

```bash
{
"code": "QWERTY",
"shortUrl": "http://localhost:5000QWERTY"
}
```

🎉 Woohoo! With a simple API call, you've crafted a test case with a mock! Dive into the Keploy directory and feast your eyes on the newly minted `test-1.yml` and `mocks.yml`

_Time to perform more API magic!_
Follow the breadcrumbs... or Make more API Calls

**2. Redirect Call**

Suppose the received code is `QWERTY`

```bash
curl -v http://localhost:5000/QWERTY
```

This is return 302 status code and redirect to the original url if code is correct.

```bash
HTTP/1.1 302 Found
Location: https://keploy.io
```

**3. Check Stats**
```bash
curl http://localhost:5000/stats/QWERTY
```

This will return the stats of the short url.

```bash
{
"clicks": 1,
"code": "QWERTY",
"createdAt": "2026-01-30T06:47:03Z",
"originalUrl": "https://keploy.io"
}
```

**4. Negative Case**
```bash
curl http://localhost:5000/XXXXXX
```

This is give error:

```bash
{
"error": "Short URL code not found"
}
```

And once you are done, you can stop the recording and give yourself a pat on the back! With that simple spell, you've conjured up a test case with a mock! Explore the **keploy** directory and you'll discover your handiwork in `tests` directory and `mocks.yml`.

Want to see if everything works as expected?

### Run Tests

Time to put things to the test 🧪

```bash
keploy test -c "docker compose up" --container-name=perl-app --delay 10
```

![alt text](/img/oss/perl-mongo-2.png)

> The `--delay` flag? Oh, that's just giving your app a little breather (in seconds) before the test cases come knocking.

### Wrapping it up 🎉

Congrats on the journey so far! You've seen Keploy's power, flexed your coding muscles, and had a bit of fun too! Now, go out there and keep exploring, innovating, and creating! Remember, with the right tools and a sprinkle of fun, anything's possible.😊🚀

Happy coding! ✨👩‍💻👨‍💻✨

<SectionDivider />

## Running App Locally on Linux/WSL/macOS 🐧

🪄 In this guide, you will set up a Perl-based URL Shortener using MongoDB and learn how Keploy enables automated API testing through record and replay modes. 🎢

<InstallReminder />

### Get Started! 🎬

Clone the repository and move to relevant folder

```bash
git clone https://github.com/Akshat005Chaudhary/keploy-perl-mongodb-quickstart.git
cd keploy-perl-mongodb-quickstart
```

Make sure you have Perl installed 🐪, Docker set up 🐳, and Keploy installed 🐰 before proceeding.

We'll be running our sample application right on Linux, but just to make things a tad more thrilling, we'll have the database (MongoDB) chill on Docker. Ready? Let's get the party started!🎉

## Install cpanm

Ubuntu:
```bash
sudo apt update
sudo apt install cpanminus -y
```
MacOS:
```bash
brew install cpanminus
```
Windows:
```bash
cpan App::cpanminus
```

## Install Dependencies

```bash
cpanm --installdeps .
```

## Start the MongoDB container

```bash
docker compose up -d mongo
```

## Confirm Server behavior

```bash
perl app.pl daemon -l http://localhost:5000
```

Should say:

```bash
Web application available at http://localhost:5000
```

### 📼 Roll the Tape - Recording Time!

Ready, set, record! Here's how:

```bash
keploy record -c "perl app.pl daemon -l http://localhost:5000"
```

![alt text](/img/oss/perl-mongo-1.png)

Keep an eye out for the `-c `flag! It's the command charm to run the app.

Alright, magician! With the app alive and kicking, let's weave some test cases. The spell? Making some API calls! Postman, Hoppscotch, or the classic curl - pick your wand.

### Let's generate the testcases.

Make API Calls using Postman or cURL command. Keploy with capture those calls to generate the test-suites containing testcases and data mocks.

**1. POST /shorten**

```bash
curl -X POST http://localhost:5000/shorten \
-H "Content-Type: application/json" \
-d '{"url":"https://keploy.io"}'
```

Here's a peek of what you get:

```bash
{
"code": "QWERTY",
"shortUrl": "http://localhost:5000QWERTY"
}
```

🎉 Woohoo! With a simple API call, you've crafted a test case with a mock! Dive into the Keploy directory and feast your eyes on the newly minted `test-1.yml` and `mocks.yml`

_Time to perform more API magic!_
Follow the breadcrumbs... or Make more API Calls

**2. Redirect Call**

Suppose the received code is `QWERTY`

```bash
curl -v http://localhost:5000/QWERTY
```

This is return 302 status code and redirect to the original url if code is correct.

```bash
HTTP/1.1 302 Found
Location: https://keploy.io
```

**3. Check Stats**
```bash
curl http://localhost:5000/stats/QWERTY
```

This will return the stats of the short url.

```bash
{
"clicks": 1,
"code": "QWERTY",
"createdAt": "2026-01-30T06:47:03Z",
"originalUrl": "https://keploy.io"
}
```

**4. Negative Case**
```bash
curl http://localhost:5000/XXXXXX
```

This is give error:

```bash
{
"error": "Short URL code not found"
}
```

And once you are done, you can stop the recording and give yourself a pat on the back! With that simple spell, you've conjured up a test case with a mock! Explore the **keploy** directory and you'll discover your handiwork in `tests` directory and `mocks.yml`.

Want to see if everything works as expected?

### Run Tests

Time to put things to the test 🧪

```bash
keploy test -c "perl app.pl daemon -l http://localhost:5000"
```

![alt text](/img/oss/perl-mongo-2.png)

### Wrapping it up 🎉

Congrats on the journey so far! You've seen Keploy's power, flexed your coding muscles, and had a bit of fun too! Now, go out there and keep exploring, innovating, and creating! Remember, with the right tools and a sprinkle of fun, anything's possible.😊🚀
29 changes: 29 additions & 0 deletions versioned_sidebars/version-4.0.0-sidebars.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,15 @@
"items": [
"quickstart/samples-csharp"
]
},
{
"type": "category",
"label": "Perl",
"collapsible": true,
"collapsed": true,
"items": [
"quickstart/perl-mongo"
]
}
]
},
Expand All @@ -129,6 +138,26 @@
"ci-cd/jenkins"
]
},
{
"type": "category",
"label": "Test Coverage Integration",
"link": {
"type": "doc",
"id": "quickstart/code-coverage"
},
"items": [
"server/sdk-installation/go"
]
},
{
"type": "category",
"label": "CI/CD Integration",
"items": [
"ci-cd/github",
"ci-cd/gitlab",
"ci-cd/jenkins"
]
},
{
"type": "category",
"label": "Test Coverage Integration",
Expand Down