Routes
#
Definition & PrinciplesRead from the Porto SAP Documentation (#Routes).
#
RulesAPI Route files MUST be named according to their API's versions, exposure and functionality. Example
CreateOrder.v1.public.php
,FulfillOrder.v2.public.php
,CancelOrder.v1.private.php
...Web Route files are pretty similar to API web files, but they can be named anything.
#
Folder Structure - app - Containers - {container-name} - UI - API - Routes - CreateItem.v1.public.php - DeleteItem.v1.public.php - CreateItem.v2.public.php - DeleteItem.v1.private.php - ApproveItem.v1.private.php - ... - WEB - Routes - main.php - ...
#
Web RoutesExample: Endpoint to display a Hello View in the browser
<?php
$router->get('/hello', [ 'uses' => 'Controller@sayHello',]);
In all the Web Routes
files the $router
variable is an instance of the default Laravel Router Illuminate\Routing\Router
.
#
API RoutesExample: User Login API Endpoint
<?php
$router->post('login', [ 'uses' => 'Controller@loginUser',]);
Example: Protected List All Users API Endpoint, for an API Routes file
<?php
$router->get('users', [ 'uses' => 'Controller@listAllUsers', 'middleware' => [ 'api.auth', ]]);
#
Protect your Endpoints:Checkout the Authorization Page.
#
Difference between Public & Private routes filesapiato has 2 types of endpoints, Public (External) mainly for third parties clients, and Private (Internal) for your own Apps. This will help to generate separate documentations for each and keep your internal API private.