REST and the Slim api -> trying to implement a backbone UI Framework

Permalink 1 user found helpful
If you were going to implement a RESTful connection to a C5 site (using Slim) in order to implement a JS UI framework (using Backbone), how would you solve the REST collision with C5 parsing the URL? Would you:

1). Launch the C5 dispatcher within Slim?

2). Use a unique symbol within the URL to Reg-Exp match the Slim portion from the C5 portion that needs to be parsed? (And then somehow make that work?)

3). ?

Ricalsin
 
ScottC replied on at Permalink Reply
ScottC
#1. require it but make sure you define the C5_ENVIRONMENT_ONLY first so it doesn't try to parse the url and render a page not found.
Ricalsin replied on at Permalink Reply
Ricalsin
Thanks, Scott. If I am just looking to perform a REST connection on specific pages - not the whole site - where would I define that?

Reviewing the dispatcher, it appears this will give me access to all of the C5 architecture but enable me to render what I want through a Slim/Backbone/underscore js UI using templates. If so, "Nice!" Thank you.
JohntheFish replied on at Permalink Reply
JohntheFish
Some wild speculation...

Skipping away from the purity of GET, POST, PUT, DELETE. Can backbone be configured to use a different url for each in a get or post? So you have the GET or POST equivalent of:
geturl?params=values
posturl?params=values
puturl?params=values
deleteurl?params=values

Then have an action in the page controller for each.
function action_get(){}
function action_post(){}
function action_put(){}
function action_delete(){}

Then deliver the C5 path for each action to configure backbone as above. That would enable the page to use C5 user permission and verification.


By giving each of the action functions a long list of parameters:
action_xx = function (p1,p2,p3,........p99){
 $args = function_get_args();
 $remaining_path = implode('/',$args);
 // slim stuff
 exit;

It could then cleanly reassemble any remaining path from backbone and use it for slim.


Another idea, implement a new direct page backbone.php that will be referenced from the backbone front end in place of C5's index.php. In it translate the standard backbone GET, PUT, POST, DELETE actions into calls that are appropriate to the above controller action functions and then pass it on to index.php or call into C5 via the dispatcher.
olsgreen replied on at Permalink Best Answer Reply
olsgreen
Probably not any use for you now, but useful for others reading this thread; I've put some Slim middleware together for booting the C5 environment & also for using C5 as an Auth database within Slim, it's up on GitHub:

https://github.com/olsgreen/slim-concrete5...

I've been building an API for an android app built on Backbone, I've completely abstracted the mobile app stuff from the main site code. Slim deals with the routing and calls C5 for data & permissions, Slim also runs on it's own sub-domain.(http://api.site.com)
RadiantWeb replied on at Permalink Reply
RadiantWeb
I just pushed a sudo-RESTfull API that has a really nice Passthrough function so you can hook into custom packages easily. Supports PUT & DELETE calls and has a half decent user/userinfo/page API built in.

https://github.com/goradiantweb/radiantweb_api...

ChadStrat