consoletvs/apify

laravel 5 的API生成器

1.0 2016-11-09 00:33 UTC

This package is auto-updated.

Last update: 2024-08-29 02:35:26 UTC


README

laravel 5 的API生成器

StyleCI StyleCI StyleCI

Apify Logo

目录

安装

要安装 apify,请使用 composer

下载

composer require consoletvs/apify

添加服务提供者及别名

将以下服务提供者添加到 config/app.php 文件中的数组中:

ConsoleTVs\Apify\ApifyServiceProvider::class,

发布资源

php artisan vendor:publish

配置

要配置该包,请访问:config/apify.php

默认文件包含有效的示例和文档,请查看,它应该看起来像这样

<?php

return [
    /*
    |--------------------------------------------------------------------------
    | Prefix used to access the API
    |--------------------------------------------------------------------------
    */
    'prefix' => 'apify',

    /*
    |--------------------------------------------------------------------------
    | Enables or disabled the whole API endpoints
    |--------------------------------------------------------------------------
    */
    'enabled' => true,

    /*
    |--------------------------------------------------------------------------
    | The tables enabled for the api and it's columns
    |--------------------------------------------------------------------------
    */
    'tables' => [

        // Specify all the tables below

        'users' => [

            // The columns from the table that will be displayed in the JSON

            'id', 'name', 'email', 'created_at', 'updated_at'

        ],

    ],
];

使用

按照以下方式访问端点

Website URL + /api/ + Prefix + /{table}/{accessor?}/{data?}

table: 是您想查看的表,必须是配置中表数组的索引。

accessor: 是可选的,它是用于过滤数据的列。

data: 是您要过滤的数据,您可以添加多个数据,并用逗号分隔。

注意:请记住,所有对API的调用首先都会发送到 api 中间件,如果需要修改API节流,请访问:App\Http\Kernel.php 并修改API节流。

'api' => [
    'throttle:60,1',
    'bindings',
],

60 决定了每分钟的调用最大次数。

1 决定了超出最大调用次数后等待的分钟数。

一些示例

http://localhost/web/Laralum3/public/api/apify/users (example URL)
{"users":[{"id":1,"name":"\u00c8rik Campobadal","email":"ConsoleTVs@gmail.com","created_at":"2016-09-22 16:13:28","updated_at":"2016-10-02 11:18:25"},{"id":2,"name":"Second User","email":"ConsoleTV2s@gmail.com","created_at":"2016-09-21 16:13:28","updated_at":"2016-09-22 16:20:00"},{"id":3,"name":"Third User","email":"ConsoleTV3s@gmail.com","created_at":"2016-08-22 16:13:28","updated_at":"2016-09-22 16:20:00"}]}
http://localhost/web/Laralum3/public/api/apify/users/email/ConsoleTVs@gmail.com,ConsoleTV3s@gmail.com (example URL)
{"users":[{"id":1,"name":"\u00c8rik Campobadal","email":"ConsoleTVs@gmail.com","created_at":"2016-09-22 16:13:28","updated_at":"2016-10-02 11:18:25"},{"id":3,"name":"Third User","email":"ConsoleTV3s@gmail.com","created_at":"2016-08-22 16:13:28","updated_at":"2016-09-22 16:20:00"}]}