How to create an API using the Laravel Dingo API Plugin Library

Source: Internet
Author: User
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!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.