本文介绍了资源 id 应该出现在 url 中吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

在资源 id 可以通过其他方式识别的情况下(例如需要身份验证的页面的 current_user),从 url 中省略 id 是个好主意吗?(例如,/students/1/homework/students/homework).

In situations where the resource id can be identified by other means (such as current_user for pages that require authentication), is it a good idea to omit the id from the url? (For example, /students/1/homework to /students/homework).

此外,这会对网址的宁静性产生任何影响吗?我怀疑它适用于 HTTP 动词,但对于自定义操作我不太确定.

Also, would this have any impact on the restfulness of the urls? I am suspecting it does for HTTP verbs, but for custom actions I am not so sure.

推荐答案

我想这取决于您的应用程序以及对客户有用的内容.如果您的连接用户是可以查看所有学生作业的管理员,则 /students/1/homework 路径是有意义的,但是如果只有学生使用此资源,则 /学生/家庭作业更有意义.
基本上后者可以被认为是所有学生资源的命名空间.
我发现通过 namespaces 拆分这些资源非常有用,以免混淆客户端编写者并保持您的授权非常明确(谁可以看到/做什么).

I suppose it is down to your application and what is useful for clients to see. If your connecting user is an admin who can see all students homework, then the /students/1/homework path makes sense, however if it will only ever be students using this resource then the /students/homework makes more sense.
Essentially the latter could be thought of as a namespace for all student resources.
I have found it very useful to split these resources by namespaces as to not confuse client writers and keep your authorisation very clear (who can see/do what).

这篇关于资源 id 应该出现在 url 中吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 13:17