Api.php
The Api.php
file is used to define routes for the application's API. These routes are typically used to provide data to client applications such as mobile apps, single-page applications (SPAs), or third-party services.
Characteristics
Stateless: API routes are usually stateless, meaning each request is processed independently without relying on previous requests.
JSON: API routes typically return data in JSON format.
Authentication: API routes often use authentication methods such as tokens, OAuth, or JWT.
Versioning: API routes are often versioned to support changes without disrupting existing client applications.
When to Use?
When you need to provide data to mobile apps or SPAs.
When you need to provide services to third-party applications or services.
When you want to build a RESTful or GraphQL API.
Example
$routes->get('/api/v1/auth/(:any)/', 'Api\V1\AuthController::$1');
$routes->post('/api/v1/auth/(:any)', 'Api\V1\AuthController::$1');
$routes->get('/api/v1/(:any)/(:any)', 'Api\V1\$1Controller::$2');
$routes->get('api/(:any)/(:any)', 'Api\$1Controller::$2');
Last updated
Was this helpful?