Multiple endpoints


#1

Hello everyone!
Is it possible to have two endpoints in the Slim?
For example, client sent requests to
GET /api/?method=auth
but also it sent requests like
GET /api/v2.php?method=admin::add_entity
Can i realize such functionality with Slim or should i choose a different method, may be server side (mod_rewrite)?
Thanks in advance!


#2

If I’m understanding your question correctly, you can have as many endpoints as you wish by adding multiple routes. Have a look at the Router documentation for adding routes.


#3

But can i use filename in the route?
I mean something like this
$app->get('/api/v2.php[{subject}]', function ($request, $response, $args) {


#4

It’s really not necessary (and not recommended) to add a .php extension to the route, but it’s possible:

$app->get('/api/v2.php', function ($request, $response, $args) {
    // ...
}

A “better” style would be without the php extension and a group for version 2 of your API.

$app->group('/api/v2', function () {

    // /api/v2/users
    $this->get('/users', function ($request, $response, $args) {

    });

    // /api/v2/customers
    $this->get('/customers', function ($request, $response, $args) {

    });
});