: This article describes how to use dingoapi. For more information about PHP tutorials, see dingoapi. Quick start
Install
composer require dingo/api:1.0.x@dev
Add dingo service provider
Openconfig/app.php
Add to providers arrayDingo\Api\Provider\LaravelServiceProvider::class
'Providers '=> [// Other service providers... 'Dingo \ Api \ Provider \ LaravelServiceProvider: class',]
Add facade
Openconfig/app.php
Add to the aliases arrayDingo\Api\Facade\API
AndDingo\Api\Facade\Route
'Aliases' => [// Other facade... 'api' => 'Dingo \ API \ Provider \ LaravelServiceProvider: class', 'apiroute '=> 'Dingo \ Api \ Facade \ Route',]
Add dingo custom configuration file
php artisan vendor:publish --provider="Dingo\Api\Provider\LaravelServiceProvider"
Command execution result:
Configure your. env file and 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
At this point, the basic configuration is complete. Next, create an API to check the effect.
Create API
Add the following code to your routing file.
$api = app('Dingo\Api\Routing\Router');$api->version('v1', function ($api) { $api->get('dingo', function () { return 'hello world'; });});
It looks like this:
Okay, you can check the effect in the browser. access address: Domain name/api/dingo
It looks like this:
The above introduces dingo/api usage, including some content, and hope to be helpful to friends who are interested in PHP tutorials.