0

I really like Restler on first blush but I wanted to make sure I could implement my requirements and my first attempt fell short but that's likely due to me not understanding it fully.

What I'd like to be able to do is have a set of families of services such as:

  • users
  • app
  • actions
  • relationships

and then be able to have a rest service such as:

Ideally I'd like to have the class definitions be segmented at the sub-type level. So in the example above I'd have a "preferences" and "goals" class that handles requests under the "user" part of the service architecture.

I've tried auto and manual routing (using @url operator) but I can't seem to get it to work.

Arul Kumaran
  • 983
  • 7
  • 23
ken
  • 8,763
  • 11
  • 72
  • 133

1 Answers1

1

Restler 2 and Restler 3 uses the class name as the path segment when path segment is not specified when we add API Class

Restler::addAPIClass($classname, $path=null); 

Map preferences and goals as follows

$r->addAPIClass('Preferences', 'user/preferences');
$r->addAPIClass('Goals', 'user/goals');

If you want to handle everything from manual routing alone (no path segment from class)

$r->addAPIClass('Preferences', '');
$r->addAPIClass('Goals', '');

and then use @url comments

Arul Kumaran
  • 983
  • 7
  • 23
  • Thanks very much but it does still leave me with a question: when adding preferences and goals via the addAPIClass() approach I can now build the service of "/users/preferences.json" but what if I want to build "/users/{id}/preferences.json"? – ken Oct 11 '12 at 07:58
  • ideally you should handle all this in user class using some manual routes for preferences and goals, those methods may internally talk to Goal and Preferences Classes for their respective outputs – Arul Kumaran Oct 11 '12 at 09:01
  • Another alternative is to map Preferences and Goals to `user` and have some manual routes for `preferences`, `{id}/preferences` etc – Arul Kumaran Oct 11 '12 at 09:03
  • Ok, thanks for you prompt help. I'll try handling it in the User class. – ken Oct 11 '12 at 09:39