且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

创建 REST 子资源来获取列表的最后一个或第一个元素是不好的做法吗?

更新时间:2023-11-25 23:13:46

在我看来,这是完全合法和可取的.我特别喜欢DELETE/notes/first的语义,但也考虑了POST/notes/first - 在第一个之前放一个新的笔记.

In my humble opinion this is perfectly legal and desirable. I especially like the semantics of DELETE /notes/first, but also consider POST /notes/first - put a new note before the first one.

在你的情况下 firstlast 是某种特殊的魔法标识符或占位符.另一方面,有哪些替代方案?

In your case first and last are some sort of special magic identifiers or placeholders. On the other hand what are the alternatives?