laravel dingo/api 安装与配置

安装好 laravel 后 ,

开始 安装 laravel dingo/api

https://github.com/dingo/api/wiki/Installation

按照 上面的 提示

composer require dingo/api:0.10.*

是直接报错了,

后来 干脆改成了

composer require dingo/api

打开 config/app.php

接着在 providers 配置里面 加上 Dingo\Api\Provider\LaravelServiceProvider::class

如下:

'providers' => [
    Dingo\Api\Provider\LaravelServiceProvider::class
]

写入 config/api.php

php artisan vendor:publish --provider="Dingo\Api\Provider\LaravelServiceProvider"

这是后就在 config文件夹下 多出了 一个 api.php 文件

配置 .env 文件

在.env 文件夹下 增加如下

API_PREFIX=api    
API_CONDITIONAL_REQUEST=false
API_STRICT=false
API_DEFAULT_FORMAT=json

到此 后面就不知道该怎么做了

下面是 文档,不理解是什么意思了

Authentication Providers

By default only basic authentication is enabled. Authentication is covered in more detail in a later chapter.

You must configure this in a published configuration file or in your bootstrap file.

$app['Dingo\Api\Auth\Auth']->extend('oauth', function ($app) {
   return new Dingo\Api\Auth\Provider\JWT($app['Tymon\JWTAuth\JWTAuth']);
});
Throttling / Rate Limiting

By default rate limiting is disabled. You can register your custom throttles with the rate limiter or use the existing authenticated and unauthenticated throttles.

You must configure this in a published configuration file or in your bootstrap file.

$app['Dingo\Api\Http\RateLimit\Handler']->extend(function ($app) {
    return new Dingo\Api\Http\RateLimit\Throttle\Authenticated;
});

到 这一步了 该怎么做呢 。,继续 该怎么做呢

有没有 laravel5.1 的 dingo/api 小demo呢

文档有些看不懂呀

阅读 18.1k
4 个回答
新手上路,请多包涵

$app['Dingo\Api\Http\RateLimit\Handler']->extend(function ($app) {
return new Dingo\Api\Http\RateLimit\Throttle\Authenticated;
});

请问一下,这个应该加在那个文件里面呢?

新手上路,请多包涵

dingo提供了Basic的验证方式,当然也可以扩展使用JWT或OAuth方式
可以先跳过鉴权部分,根据wiki创建一些API路由试试,等差不多了再回头调试验证部分

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题