Home >PHP Framework >Laravel >What is dingo in laravel

What is dingo in laravel

WBOY
WBOYOriginal
2022-02-23 16:39:392754browse

In laravel, dingo is an API development toolkit for laravel and lumen frameworks; it mainly has three functions: routing version management, "Http Exception" exception handling and "Response Transform" conversion response format.

What is dingo in laravel

#The operating environment of this article: Windows 10 system, Laravel version 6, Dell G3 computer.

What is dingo in laravel

dingo is an API development toolkit for laravel and lumen frameworks.

Looking at the document directory, based on the API specification, it revolves around three main functions:

  • Routing version management

  • Http Exception exception handling

  • Response Transform Conversion response format

dingoapi is an open source plug-in for laravel, which can be searched on github. It is now When working on a project, there will always be json data interaction between the backend and the frontend in the project, and this dingoapi provides great convenience for json interaction.

Routing version control

1. Related configuration

1Declare api service

The api specification requires that interface development must either have an api prefix (http://XXX.com/api/xxx) or a subdomain name (http://api.XXX.com/xxx). Through such identification, Represents the request for an API interface service.

So, one of API_PREFIX=api and API_DOMAIN=api.myapp.com must be set.

.env options that may need to be configured

Of course, its role is not just an identifier. We know that dingo’s routing and laravel’s routing coexist, and dingo uses this feature to determine .

2 Version Control

dingo provides its own routing service, if http://XXX.com/api/xxx or http://api.XXX. com/xxx is accessed, it considers it an api request. The dingo routing service Dingo\Api\Routing\Router will take over laravel's own routing service Illuminate\Routing\Router (as for how to take over, I will talk about it later), it also has get (), post(), match(), group()... methods are equivalent to another routing system.

If laravel distinguishes versions, you may need to bring a v1 prefix, such as http://XXX.com/api/v1 or http://XXX.com/api/v2. And dingo is processed through the header Accept. Its format is Accept: application/vnd.YOUR_SUBTYPE.v1 json. It means that you need to send an accept request header to access.

In the configuration file, this mode is not mandatory by default, API_STRICT=false, but you can only access the default version in the configuration file, 'version' => env('API_VERSION', 'v1') ,.

If set to true, that is, strict mode is turned on, the accept header must be sent, and your API cannot be accessed directly through the browser.

.env options that may need to be configured

API_STRICT=true //To enable strict mode, you must bring the accept header information regardless of v1 or v2

API_VERSION= v1 //The default version number when no version number is declared

If strict mode is turned on

There are several options for the accept attribute of the header:

Accept: application/vnd.YOUR_SUBTYPE.v1 json

API_STANDARDS_TREE=x,prs,vnd Standards Tree Standards Tree

API_SUBTYPE=myapp Subtype: short name of the program or project

v1 : Version number

json: The returned format can also be jsonp

.env Options that may need to be configured

API_STANDARDS_TREE=prs

API_SUBTYPE=lara

API_DEFAULT_FORMAT=json //Default

[Related recommendations: laravel video tutorial

The above is the detailed content of What is dingo in laravel. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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