Dingo/api use

Source: Internet
Author: User
Tags aliases
Quick to use


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_name= "My API"

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.

  • 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.