This article mainly introduces the use of Laravel Dingo API plug-in library to create an API method, has a certain reference value, now share to everyone, have the need for friends can refer to
Creating APIs with Laravel is a method that many large projects are using, typically using the Dingo API plug-in library to develop their own APIs. Here are some of the Ytkah with Dingo API, a friend in need to pay attention to
1. Installation
Because the version of the Dingo API needs to be compatible with the Laravel version, you need to add a specific version number, or you may get an error
cannot be installed as shown
The right way to do this is to add a specific version within the
Composer require dingo/api ' V2.0.0-ALPHA2 '
Note: V2.0.0-ALPHA2 support Laravel 5.6,V2.0.0-ALPHA1 support Laravel 5.5, specific version to see the release log description https://github.com/dingo/api/releases
Or in the second way
Add in Composer.json
"Require": { "Dingo/api": "2.0.0-ALPHA2"//}
Set minimum-stability to Dev because V2.0.0-alpha2 is still in the development state, not a stable version
Then run update composer updates
2. Release
PHP artisan vendor:publish--provider= "Dingo\api\provider\laravelserviceprovider"
Setting the Dingo API
Now it's time to develop your API. If you are using Laravel 5, you can set up various packages through. Env, some of which need to be published publish, implemented with the following instructions, or can be implemented by configuring the Appserviceprovider.
PHP artisan vendor:publish--provider= "Dingo\api\provider\laravelserviceprovider"
--------------------
Settings for. env
API_STANDARDS_TREE=VND//Standard tree Api_subtype=ytkahapp//abbreviation, must lowercase api_prefix=api//prefix
Of course you can also use a separate domain to configure the API (optional, not required)
Api_domain=api.ytkahapp.com
Configure the version number (if not labeled, the default version is called)
Api_version=v1
Set the API name with double quotation marks ""
Api_name= "My API"
Some other settings
Api_conditional_request=falseapi_strict=false//Strict mode Api_debug=true//Turn on debug mode
The above is the whole content of this article, I hope that everyone's learning has helped, more relevant content please pay attention to topic.alibabacloud.com!