Home >Backend Development >PHP Tutorial >dingo/api use
Quick use
<code>composer require dingo/api:1.0.x@dev</code>
Open config/app.php
Add DingoApiProviderLaravelServiceProvider::class to the providers array
<code>'providers' => [ // 其他的服务提供者... 'Dingo\Api\Provider\LaravelServiceProvider::class', ]</code>
Openconfig/app.php
Add DingoApiFacadeAPI
and DingoApiFacadeRoute
<code>'aliases' => [ // 其他的facade... 'API' => 'Dingo\Api\Provider\LaravelServiceProvider::class', 'ApiRoute' => 'Dingo\Api\Facade\Route', ]</code>
<code>php artisan vendor:publish --provider="Dingo\Api\Provider\LaravelServiceProvider"</code>
Execute the command results:
API_STANDARDS_TREE=vnd
API_SUBTYPE=myapp
API_PREFIX=api
API_VERSION=v1
API_NAME="My API"
API_C>API_STRICT=false
API_DEBUG=true
API_DEFAULT_FORMAT=json
At this point, the basic configuration is basically completed Now, create an API to see the effect
into your routing file and put the following code in it
<code>$api = app('Dingo\Api\Routing\Router'); $api->version('v1', function ($api) { $api->get('dingo', function () { return 'hello world'; }); });</code>
It looks like this:
Okay, you can browse Check the effect on the server. The access address: domain name/api/dingo
looks like this:
The above introduces the use of dingo/api, including aspects of the content. I hope it will be helpful to friends who are interested in PHP tutorials.