MongoDB REST Interface

Looking at the list of REST Interfaces listed on Mongo's site, there isn't a Perl solution. Well this just won't stand. So after looking at the python program to see if I missed something about what this would entail, I hacked out this gist.

There are some limitations - you have to let mongo generate your _id - and the PUT /:db/:collection/:id route doesn't use the id portion from the route; it's this way to work with the JS framework generated URLs I am working with, and some of the code could be abstracted more. However, all in all, this should be a good base for anyone wanting to start with mongo but not touch the shell UI to get a db up and going. The other use is a quick, 'no backend' style setup where front end devs may not know their data structure and just want a data conduit to throw ajaxy requests at. While creating this, I had three lines that setup a Test::mongod instance and fed the port to MongoDB::Client. Like that, you just install the mongod libs, cpanm Test::mongod, launch and tell your frontend devs where to point their REST client - done.

This was so trivial to write up, I don't see why Perl couldn't have several options in whatever your flavor of the day framework is - that is our way right?

Leave a comment

About Jesse Shy

user-pic Perl pays for my travel addiction.