How to tell between a nonexistent service or a lack of a record?

落花浮王杯 提交于 2019-12-14 03:52:46

问题


I'm making some REST services, and as I'm implementing a GET request, I was debating about what I should do if there is no record there, for example /profile/1234. Now, if you tried to use /profiles/1234 (note the s on profiles) it would definitely be a 404 code because that URL definitely isn't found. But when it comes to there just being no 1234 profile, I'm not sure what I should return. I don't want to return {} because that might give the impression there is a record with no data. But if I return a 404 error code, how is the consumer of the API supposed to tell the difference between the two 404s?

How can I be a responsible API designer by communicating programmatically what the difference between a service that doesn't exist and a record that doesn't exist?


回答1:


You can send a custom status message which will help you differentiate between the "different" 404s.

On the other hand, I wouldn't worry about that distinction. People are used to having to type api endpoints carefully. As long as they manually test their app a tiny bit the issue becomes a non-issue.



来源:https://stackoverflow.com/questions/25957056/how-to-tell-between-a-nonexistent-service-or-a-lack-of-a-record

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!