| 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 |
|
|||||||
| keyword |
|
import Link from '@docusaurus/Link' import InstallReminder from '@site/src/components/InstallReminder'; import SectionDivider from '@site/src/components/SectionDivider';
🪄 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. 🎢
Clone the repository and move to relevant folder
git clone https://github.com/Akshat005Chaudhary/keploy-perl-mongodb-quickstart.git
cd keploy-perl-mongodb-quickstartWe will be using Docker compose to run the application as well as Mongo on Docker container.
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.
keploy record -c "docker compose up" --container-name=perl-app🔥 Challenge time! Generate some test cases. How? Just make some API calls. Postman, Hoppscotch or even curl - take your pick!
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
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:
{
"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
curl -v http://localhost:5000/QWERTYThis is return 302 status code and redirect to the original url if code is correct.
HTTP/1.1 302 Found
Location: https://keploy.io3. Check Stats
curl http://localhost:5000/stats/QWERTYThis will return the stats of the short url.
{
"clicks": 1,
"code": "QWERTY",
"createdAt": "2026-01-30T06:47:03Z",
"originalUrl": "https://keploy.io"
}4. Negative Case
curl http://localhost:5000/XXXXXXThis is give error:
{
"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?
Time to put things to the test 🧪
keploy test -c "docker compose up" --container-name=perl-app --delay 10The
--delayflag? Oh, that's just giving your app a little breather (in seconds) before the test cases come knocking.
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! ✨👩💻👨💻✨
🪄 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. 🎢
Clone the repository and move to relevant folder
git clone https://github.com/Akshat005Chaudhary/keploy-perl-mongodb-quickstart.git
cd keploy-perl-mongodb-quickstartMake 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!🎉
Ubuntu:
sudo apt update
sudo apt install cpanminus -yMacOS:
brew install cpanminusWindows:
cpan App::cpanminuscpanm --installdeps .docker compose up -d mongoperl app.pl daemon -l http://localhost:5000Should say:
Web application available at http://localhost:5000Ready, set, record! Here's how:
keploy record -c "perl app.pl daemon -l http://localhost:5000"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.
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
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:
{
"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
curl -v http://localhost:5000/QWERTYThis is return 302 status code and redirect to the original url if code is correct.
HTTP/1.1 302 Found
Location: https://keploy.io3. Check Stats
curl http://localhost:5000/stats/QWERTYThis will return the stats of the short url.
{
"clicks": 1,
"code": "QWERTY",
"createdAt": "2026-01-30T06:47:03Z",
"originalUrl": "https://keploy.io"
}4. Negative Case
curl http://localhost:5000/XXXXXXThis is give error:
{
"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?
Time to put things to the test 🧪
keploy test -c "perl app.pl daemon -l http://localhost:5000"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.😊🚀

