Compojure and mongodb for API



I am currently looking into creating a JSON api with compojure and was wondering if anyone has got good examples laying around.

I currently use compojure (handler/api) and monger.

But serializing ObjectId is not working.

I saw that there is a compojure-api ( ) but don’t know if that is a good tool for this?


Hi there!

What library are you using to write out JSON? The ones I know of all have ways of adding new serializers for different types.

Check out this:

If that doesn’t help, let me know what library you are using.



I just created a repo on github

So basically I am using


I started out with

and am trying to switch out the in memory db with mongodb.

Have not had the time to read the article you refered to, but will do as soon as I can find the time.


Ok, Here’s what I would try:

(cheshire.generate/add-encoder org.bson.types.ObjectId cheshire.generate/encode-str)

If all the namespaces are required, that should work. You will have to run it before the first web request.


Thanks I got it working now, I did need to add genereate-string as well, but you can see that in the repo on github


Great! I’m glad you got it working.