Routing works the exact same way as it does in Laravel/Lumen (depending on where you're using this pacakge).
Your code is partly correct. When you use $api->get
you only need to provide the URI it responds to and the action that should be taken. The third parameter is not required.
So it should look like this:
$api->get('users', 'UserController@index');
Now when you browse /api/users
it will look for the UserController
and use the index
method. It should be worth noting that you may need to include the full namespace to the controller, e.g., App\Http\Controllers
for a fresh Laravel install.
You can utilize the other HTTP verbs as well, much like in Laravel/Lumen.
$api->post('users', 'UserController@create');
Finally, you can utilize resource controllers, which is what the third parameter is for in your example.
$api->resource('users', 'UserController', ['only' => ['index', 'create']]);
Note: All of these must be contained within an API version group, e.g., $api->version('v1', function ($api) { });