Dingo/api usage

Source: Internet
Author: User
: 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.phpAdd to providers arrayDingo\Api\Provider\LaravelServiceProvider::class

'Providers '=> [// Other service providers... 'Dingo \ Api \ Provider \ LaravelServiceProvider: class',]
Add facade

Openconfig/app.phpAdd to the aliases arrayDingo\Api\Facade\APIAndDingo\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.

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.