Dingo API-如何在网址中添加版本号? [英] Dingo API - How to add version number in url?
问题描述
我刚刚安装了Dingo,它似乎可以使用以下URL:
I have just installed Dingo and it appear to work with the following URL:
$api = app('Dingo\Api\Routing\Router');
$api->version('v1', function ($api) {
$api->get('test', function () {
return 'Test';
});
$api->get('hello', function () {
return 'Hello';
});
});
我希望版本1包含在URL中,如何使它工作? 当我尝试时:
I would like version v1 to be included in the URL, how do I get this to work? When I try:
http://website.dev/api/v1/test
我收到错误消息:
{
"message": "404 Not Found",
"status_code": 404
}
在.env
文件中,我有:API_PREFIX=api
根据 Dingo配置:
避免将版本号作为前缀或子域 版本控制是通过Accept标头处理的.
Avoid putting a version number as your prefix or subdomain as versioning is handled via the Accept header.
推荐答案
dingoAPI的版本无法通过这种方式工作.由于它们未在URI中对API进行版本控制,因此您需要定义一个Accept标头以请求特定版本.标头的格式如下:
The version of dingoAPI don't work this way. Because they aren't versioning the API in the URI, you need to define an Accept header to request a specific version. The header is formatted like so:
Accept: application/vnd.YOUR_SUBTYPE.v1+json
For accessing the version you will need a HTTP Client like postman
这篇关于Dingo API-如何在网址中添加版本号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!