Creating an API for a module
I can't seem to figure out how to create a RESTful API for a custom module.
I'm using Asgard v2.0
I've created the module with the scaffold tool. I'm guessing the API endpoints should be defined in the apiRoutes file but I can't get it to work.
I finally figured it out.
The problem was that the route was pointing to a controller that didnt exist. A simple typo.
So this is what I did:
- Created a new module using the scaffold tool named Installations
- Created a new controller to /Modules/Installations/Http/Controllers/Api/InstallationsController.php
- Created a new routes file to /Modules/Installations/Http/apiRoutes.php and added the file path to the getApiRoute() in the RouteServiceProvider.php
The route itself is nothing special:
$router->get('installations/test', ['as' => 'api.installations.test', 'uses' => 'InstallationController@test']);