Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the function of dingo in laravel

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "what is the role of dingo in laravel". In daily operation, I believe that many people have doubts about the role of dingo in laravel. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts of "what is the role of dingo in laravel?" Next, please follow the editor to study!

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

This article operating environment: Windows10 system, Laravel6 version, Dell G3 computer.

What is dingo in laravel

Dingo is an api development kit for laravel and lumen frameworks.

A rough look at the document directory, based on the api specification, revolves around three main functions:

Routing version management

Http Exception exception handling

Response Transform transform response format

Dingoapi is an open source plug-in for laravel, which can be searched on github. Now we are working on a project in which there will always be back-end and front-end json data interaction, and this dingoapi provides great convenience for json interaction.

Routing version control

I. related configuration

1 declare api service

The api specification requires that interface development be developed with either an api prefix (http://XXX.com/api/xxx) or a subdomain name (http://api.XXX.com/xxx). Through such an identification, it represents a request for an api interface service.

Therefore, API_PREFIX=api and API_DOMAIN=api.myapp.com must be set up one of them.

Options that .env may need to configure

Of course, its function is not just an identification, we know that the routing of dingo and laravel coexist, and dingo is judged by this feature.

2 version control

Dingo provides its own routing service. If http://XXX.com/api/xxx or http://api.XXX.com/xxx access, it considers it to be an api request. The dingo routing service Dingo\ Api\ Routing\ Router will take over the routing service Illuminate\ Routing\ Router (as to how it is taken over later). It also has get (), post (), match (), group ()... Method, which is equivalent to another routing system.

If laravel is version-sensitive, you may need to have a v1 prefix, such as http://XXX.com/api/v1 or http://XXX.com/api/v2. Dingo is handled by the header 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 it.

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

If it is set to true, that is, strict mode is turned on, you must send an API header and you cannot access your browser directly.

Options that .env may need to configure

API_STRICT=true / / the strict mode must be turned on regardless of v1 and v2 must be equipped with header information.

API_VERSION=v1 / / the default version number if the version number is not declared

If strict mode is turned on

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

Accept: application/vnd.YOUR_SUBTYPE.v1+json

API_STANDARDS_TREE=x,prs,vnd Standards Tree standard tree

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

V1: version number

Json: returned format, which can also be jsonp

Options that .env may need to configure

API_STANDARDS_TREE=prs

API_SUBTYPE=lara

API_DEFAULT_FORMAT=json / / default

At this point, the study on "what is the role of dingo in laravel" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report