Routes 本文未发布 发布文章

未匹配的标注

Definition & Principles

Read from the Porto SAP Documentation (#Routes).

Rules

  • The API Routes 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 Routes 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 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.

本文章首发在 LearnKu.com 网站上。

上一篇 下一篇
《L05 电商实战》
从零开发一个电商项目,功能包括电商后台、商品 & SKU 管理、购物车、订单管理、支付宝支付、微信支付、订单退款流程、优惠券等
《L04 微信小程序从零到发布》
从小程序个人账户申请开始,带你一步步进行开发一个微信小程序,直到提交微信控制台上线发布。
讨论数量: 0
发起讨论 查看所有版本


暂无话题~