Hello folks,
I have two principal questions, one is kinda linked to another.
Question One: Regex Routing
I wanted to do “dynamic” routing, so I used RegEx to match something like this:
GET - api/library/2/books/3/5/10/33/…/pages
I declared the route like this ( Don’t pay too much attention on the code its just an example ):
$app->group('/library', function () {
$this->group('/{library_id}', function(){
$this->group('/books/{books_id:[\d(\/)*]+}', function(){
$this->get('',BooksController::class . ':getSelectedBooks');
});
});
});
The thing is that when I use $request->getAttribute(‘routeInfo’)[2] I get something like that:
“books_id”: “1/2/3/4”
I know I can always explode that and turn it into an array but does Slim have this functionality embedded ?
Question Two: Recomended Method to do that.
The operation above retrieve of all books only the ones that are into the request. It is clearly a GET operation.
From your perspective what is better ( pro/cons ) of doing those two bellow:
- Using GET
GET - api/library/2/books/3/5/10/33/…/pages
- Using POST
POST - api/library/2/books/pages
Body:
{
"books_id": [
2,
30,
40,
20,
30
]
}
Thanks,
LosLobos.