Backbone.js and ColdBox?

Anyone have any experience integrating Backbone.js with a ColdBox application? This kind of fits in line with my previous questions about viewlets.

I would love to see any example code if anyone could share. I’m particularly interested in the routes configuration and how the handlers are put together.

Cheers!
Ben

Yes Ben. I love Backbone and I love ColdBox. Yeah!

We recently built a mobile application that uses Backbone. However, it is a departure from traditional application design as we use a layout/view for the intital rendering. Subsequent requests are all API driven. Anything that is rendered by Backbone.js occurs using underscore templates and JSON data provided by the API.

Good news: I’m working on an example of an open source application using Backbone and ColdBox that I hope to share within the next few weeks.

-A

I should also note: You can see my Learning Backbone.JS application from last year here: https://github.com/aarongreenlee/Learning-backbone.js and presentation here http://www.meetup.com/florida-web-developers/messages/boards/thread/10389695

Hi Aaron,

I’m doing some Backbone.js work at the moment. I’ve got a nice working front-end now which is using a local browser storage adaptor for the sake of development.

However, we’re now starting to look at integration of the front-end with the ColdBox back end.

The default backbone.js sync stuff appears to be very rails oriented in it’s approach to how requests are made.

Have you put together your own backbone sync wrapped for Coldbox / Coldfusion?

Thanks.

Robert

I’ve not written any wrapper, but, ColdFusion (again) makes this pretty easy for us.

You just need to extract the data from the body of the request:

local.yourDataAsJSON = toString( getHttpRequestData().content);

Hope that helps.

-A

Thanks Aaron,

And that works the same for DELETE and PUT requests from backbone?

Robert

Yes, I know it works for PUT. I am not sure about delete. My API extracts the id from the URL in that instance. I have never tried looking into the body of a delete request as there are no params I care about.

Be sure you share your project here!

Aaron

I’ve had good luck doing this.

First,

I made an interceptor: https://gist.github.com/1118410
This handles the default JSON requests.

I added a route to have a default attribute /:id? for the end of the urls…

Then I created restful handlers, specifying the request method like so:
https://gist.github.com/277ff345f03ebcf8275e

There are probably better ways of handling this, but I found this to be the easiest way for me to handle the requests.

When returning data I do it like so:
event.renderData(type=‘json’,data=surveyStruct);

A small gotcha here is that if you use the default object, your serialization will have all properties be in all caps. To get around this, I simply added a getStruct() method for my entities that I’m dealing with and make a new struct and set the properties using the struct[‘property’] syntax. In doing so, I’m able to control the case of the properties and the json serialization respects this.

Good luck! let me know if you have ANY questions…

Ben

Thanks Aaron & Ben,

I’ll put some thought into it and see how I get on. Perhaps RELAX will come into the mix instead of that interceptor approach? Both would be a perfectly nice solution!

I’ll be sure to share anything that I produce with the gang.

Appreciate the advice / help guys. As a cross-post, I have a question running over on the Backbone mailing list about object relationships, something you guys may know how to deal with?

https://groups.google.com/forum/#!topic/backbonejs/2G8bFyqbvfI

Robert

I have also been doing what Aaron suggested with normal event handlers, no need for an interceptor and I am the same as Aaron haven’t done any delete requests as yet, but that is coming as most of my stuff is FaceBook related at the moment.

I have also been doing what Aaron suggested with normal event handlers, no need for an interceptor and I am the same as Aaron haven’t done any delete requests as yet, but that is coming as most of my stuff is FaceBook related at the moment.