GitHub Repository

apiato

Definition & Principles

Read from the Porto SAP Documentation (#Routes).

Rules

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 Routes

Example: 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 Routes

Example: 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 files

apiato has 2 types of endpoints, Public (External) mainly for third parties clients, and Private (Internal) for your own Apps. This will help generating separate documentations for each and keep your internal API private.