Quick to use
Installation
composer require dingo/api:1.0.x@dev
Add Dingo service Provider
Open config/app.php
the Add to providers arrayDingo\Api\Provider\LaravelServiceProvider::class
'providers' => [ // 其他的服务提供者... 'Dingo\Api\Provider\LaravelServiceProvider::class',]
Add facade
Opens config/app.php
the add to aliases array Dingo\Api\Facade\API
andDingo\Api\Facade\Route
'aliases' => [ // 其他的facade... 'API' => 'Dingo\Api\Provider\LaravelServiceProvider::class', 'ApiRoute' => 'Dingo\Api\Facade\Route',]
Add a dingo custom configuration file
php artisan vendor:publish --provider="Dingo\Api\Provider\LaravelServiceProvider"
To execute the command result:
Configure your. env file to add the following content to your. env file
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
Here, the basic configuration is basically finished, create an API below to see the effect
Creating an API
Into your routing file, put the following code in
$api = app('Dingo\Api\Routing\Router');$api->version('v1', function ($api) { $api->get('dingo', function () { return 'hello world'; });});
Looks like this:
OK, you can go to the browser to see the effect, Access address: domain name/api/dingo
Looks like this:
The above describes the use of DINGO/API, including aspects of the content, I hope that the PHP tutorial interested in a friend helpful.