Comments (9)
为什么算bug 啊,没有link就是没有资源相关的其他链接了。不然应该返回啥呢
from lumen-api-demo.
客户端这边反映的,他们认为links这里如果是统一是一个“对象”就是应该给对象格式,而不是数组格式
from lumen-api-demo.
"meta": {
"pagination": {
"total": 11,
"count": 11,
"per_page": 20,
"current_page": 1,
"total_pages": 1,
"links": []
}
}
以上这种应该要换成这种
"meta": {
"pagination": {
"total": 11,
"count": 11,
"per_page": 20,
"current_page": 1,
"total_pages": 1,
"links": {}
}
}
才是格式统一的
from lumen-api-demo.
凭什么 links 必须是个对象,给出合理的解释,统一返回数组怎么了
from lumen-api-demo.
links空值的时候是以上那样的,如果是非空值的时候长这样:
"meta": {
"pagination": {
"total": 11,
"count": 2,
"per_page": 2,
"current_page": 2,
"total_pages": 6,
"links": {
"previous": "http://api.com/api/users?page=1",
"next": "http://api.com/api/users?page=3"
}
}
}
这里links是一个对象,格式不统一,对于客户端而言,这里解析的时候,要判断links的类型
from lumen-api-demo.
因为有值得时候是对象,抱歉才看明白,那么我觉得没值得时候返回 "links": null 比较好,空对象不是很奇怪吗。我看看代码怎么改
from lumen-api-demo.
我认为是php语法糖的原因,大家都喜欢数组太习惯了,这里本身严格来说应该是对象定义的,我自己这里私下加了一句,
if(empty($pagination['links'])){
$pagination['links'] = new \stdClass();
}
我觉得是{}比null好,在w3c里面给出的json说明中是这样描述的
数据在名称/值对中
数据由逗号分隔
花括号保存对象
方括号保存数组
既然这里已经是对象了,那它应该是{}来表明类型了,明天我再和客户端讨论下,看看他们那里解析器是什么行为。
from lumen-api-demo.
你可以参考 https://github.com/liyu001989/dingo-serializer-switch/tree/master 我这个项目的做法,自己修改一下serializer。null理解起来很通顺,我改成null了。你按照自己的理解修改。
友情提示,不要直接修改vendor中的文件,不要提交vendor到版本库
from lumen-api-demo.
好的,多谢,vendor中的东西我生产环境中不会去动的,这里暂时只是做实验。你的restful理解那篇文章写得很好,我安利给现在项目组的同事了,感谢分享。
from lumen-api-demo.
Related Issues (20)
- Using Session inside Lumen HOT 2
- 请问能使用模糊查询吗 HOT 5
- put接收不到数据 HOT 2
- wrong assignment in base repo HOT 2
- http://lumen.com/api/users HOT 3
- need authentication的情况下,发送带有token的header,会返回The Response content must be a string or object implementing __toString(), \"boolean\" given. HOT 4
- 请教一个在lumen+dingo+jwt+laravel_wechat的环境下的问题 HOT 17
- 想请教一下使用JWT的时候token这部分怎么自己定义呢? HOT 4
- 请教一个关于dingo api的问题 HOT 8
- 接口是使用policy ,报错 “This action is unauthorized” HOT 2
- laravel 路由模型绑定不能在dingo中生效? HOT 1
- cors功能貌似有问题 HOT 1
- 有个地方有点问题 HOT 1
- 有没有对应的后台admin HOT 1
- 数据库无法连接?
- 请问,如果我想在transformer层控制权限怎么整呢?
- transformer是否适用于关联查询
- Auth driver [jwt] for guard [api] is not defined. HOT 1
- please man remove the link found in the repo description
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lumen-api-demo.