REST ->map() to one or several classes

42 views
Skip to first unread message

Anatol

unread,
Jan 8, 2017, 4:23:23 AM1/8/17
to Fat-Free Framework
Hi,

if /dogs is for the collection and /dogs/@name for a specific dog
do you normally map to several classes like:

$f3->map('/dogs/','\api\dogs');
$f3
->map('/dogs/@name','\api\dog');

Or is it common to implement some logic to handle both cases in one class:

function get(\base $f3){
   
if (i
sset($f3->get(@name)) ){
       echo "I have to do something with a specific dog namend ..." . $f3->get(@name);
    } else {
       echo
"It´s about the whole pack and their names are: ....";
   
}
}


The question comes up as both cases are about dogs from that I would say it should be the concern of
one class handling it. On the other hand I´d like to avoid ending with one big class where it´s getting
hard to see which route is bound to which part.

thank you !

– anatol










bcosca

unread,
Jan 8, 2017, 5:29:20 AM1/8/17
to f3-fra...@googlegroups.com
I have always been inclined towards a single class to handle both categories and specific entities.

ikkez

unread,
Jan 8, 2017, 8:39:39 AM1/8/17
to Fat-Free Framework
same here. I check the params in a base class, which then delegates to getSingle or getCollection methods.

Anatol

unread,
Jan 9, 2017, 3:59:45 AM1/9/17
to Fat-Free Framework
Hi Bong and Ikkez,

thanks for your replies. Extending a base class sounds good. Thanks!

One more question. Have you ever implemented OPTIONS? I´m unsure how this should be done maybe by help of
a reflection class?

cheers,

– anatol 

ikkez

unread,
Jan 9, 2017, 4:54:02 AM1/9/17
to Fat-Free Framework
OPTIONS is implemented in the F3 router and handled automatically. IMO there's no need to care about it unless you have a very special use case for it (cannot imagine anything yet)

Anatol

unread,
Jan 9, 2017, 11:33:01 AM1/9/17
to Fat-Free Framework
Great to hear!
Thanks a lot!
Reply all
Reply to author
Forward
0 new messages