dingo/api use

WBOY
Release: 2016-07-29 08:56:42
Original
2375 people have browsed it

Quick use

Install

<code>composer require dingo/api:1.0.x@dev</code>
Copy after login

Add dingo service provider

Open config/app.php Add DingoApiProviderLaravelServiceProvider::class to the providers array

<code>'providers' => [
    // 其他的服务提供者...

    'Dingo\Api\Provider\LaravelServiceProvider::class',
]</code>
Copy after login

Add facade

Openconfig/app.php Add DingoApiFacadeAPI and DingoApiFacadeRoute

<code>'aliases' => [
    // 其他的facade...

    'API' => 'Dingo\Api\Provider\LaravelServiceProvider::class',
    'ApiRoute' => 'Dingo\Api\Facade\Route',
]</code>
Copy after login

to the aliases array. Add dingo custom configuration file

<code>php artisan vendor:publish --provider="Dingo\Api\Provider\LaravelServiceProvider"</code>
Copy after login

Execute the command results:
dingo/api use

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 basically completed Now, create an API to see the effect


Create the API

into your routing file and put the following code in it

<code>$api = app('Dingo\Api\Routing\Router');

$api->version('v1', function ($api) {
    $api->get('dingo', function () {
        return 'hello world';
    });
});</code>
Copy after login

It looks like this:

dingo/api use


Okay, you can browse Check the effect on the server. The access address: domain name/api/dingo

looks like this:

dingo/api use

The above introduces the use of dingo/api, including aspects of the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template