-
-
Notifications
You must be signed in to change notification settings - Fork 290
Add Perl + MongoDB Quickstart (Addressed review feedback) #851
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Akshat005Chaudhary
wants to merge
8
commits into
keploy:main
Choose a base branch
from
Akshat005Chaudhary:akshat-branch-one
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e538941
Add Perl + MongoDB quickstart
690280c
Fixed Issues pertaining to issue 774
980f878
Merge branch 'main' into akshat-branch-one
amaan-bhati 23445b3
Merge branch 'main' into akshat-branch-one
amaan-bhati 539d409
docs: address PR review feedback for Perl MongoDB quickstart
b4564a8
Merge branch 'main' into akshat-branch-one
amaan-bhati d0f6296
docs: address PR review feedback on perl-mongo quickstart
bba73fa
Merge branch 'main' into akshat-branch-one
dhananjay6561 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,310 @@ | ||
| --- | ||
| 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 InstallReminder from '@site/src/components/InstallReminder'; | ||
| import SectionDivider from '@site/src/components/SectionDivider'; | ||
|
|
||
| ## Running App 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/keploy/samples-perl.git | ||
| cd samples-perl | ||
| ``` | ||
|
|
||
| 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 | ||
| ``` | ||
|
|
||
|  | ||
|
|
||
| 🔥 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 will 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:5000/QWERTY" | ||
| } | ||
| ``` | ||
|
|
||
| 🎉 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 will 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 will give an 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 | ||
| ``` | ||
|
|
||
|  | ||
|
|
||
| > 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/keploy/samples-perl.git | ||
| cd samples-perl | ||
| ``` | ||
|
|
||
| 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" | ||
| ``` | ||
|
|
||
|  | ||
|
|
||
| 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 will 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:5000/QWERTY" | ||
| } | ||
| ``` | ||
|
|
||
| 🎉 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 will 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 will give an 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" --delay 10 | ||
| ``` | ||
|
|
||
|  | ||
|
|
||
| ### 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.😊🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This anchor looks like it'll break. The heading in the guide is
## Running App Locally on Linux/WSL/macOS 🐧, which Docusaurus slugifies torunning-app-locally-on-linuxwslmacos-— but this link points torunning-app-locally-on-linuxwsl-(missingmacos), so the "Local" card won't scroll to the right section.The existing samples use the heading
Running App Locally on Linux/WSL 🐧(no/macOS), which is why their#running-app-locally-on-linuxwsl-anchors work. Easiest fix: match that heading in the guide, otherwise update this link to#running-app-locally-on-linuxwslmacos-.