Perl Petstore Enhanced REST API Framework

Perl LogoI’ve been doing a lot of work with REST APIs and microservices, so I decided to write a complete REST API framework in Perl based on the Mojolicious and Swagger2 Petstore sample.

You can git clone the repo and add a new API endpoint in about 5 minutes with automatic parameter validation and documentation:

git clone
cd perl-petstore-enhanced/pets
less ../
vi api.spec cgi-bin/pets.cgi ./lib/Pets/Controller/
# add an Alias for cgi-bin/pets.cgi to httpd or nginx
# point your browser at
# Good job. Have a Modelo! :)

or you can spend an hour to rename the files for your project and tweak it to requirements.

This project serves as a convenient bridge for those who:

  1. can write simple CGI programs and want to write a best-practises Swagger (OpenAPI) REST API server without climbing a steep learning curve, or
  2. want to write a quick proof-of-concept API server to be re-implemented in other languages or frameworks later, as your Swagger spec file is 100% reusable
  3. are targeting a small VM. This will work in a 2 GB RAM VM just fine, or on an existing server running httpd or nginx.

Also of note is the samples/ folder, which has non-trivial client programs in several languages (bash, Java, Perl, PHP and Ruby.)

I learned the importance of Swagger2 and auto-generated API documentation and validation when I was programming with the old Rackspace Cloud v1 and v2 APIs.

People asked me, “How did you get anything to work? You must have really wanted it!” since the Rackspace sample code, docs and live API didn’t match each other. My secret: I actually guessed URLs in the browser to find the endpoints I needed. Swagger prevents that headache.
Swagger UI 10 realizations as I was creating my Swagger spec and Swagger UI

Are microservices for you? You might be asking the wrong question. List of default Accept values

This entry was posted in API Programming, Open Source, Perl, Tech. Bookmark the permalink.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.