且构网

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

REST API - 包括有关对象的详细信息或者只是ID的

更新时间:2022-12-07 11:58:36

这倒是REST的核心原则之一叫做HATEOAS(超媒体作为应用程序状态引擎)。

This touches one of the core principles of REST called HATEOAS (Hypermedia As The Engine Of Application State).

对象ID是无用的,毫无意义的客户。你怎么跟他们做什么?它们提供给搜索功能?构造一个新的URI与他们追加到它的结束?电话1-800号码,并要求他们做什么?打印出来的纸张和邮寄给***机构,帮助客户API找到自己的下一步?

Object IDs are useless and meaningless to clients. What do you do with them? Feed them to a search function? Construct a new URI with them appended to the end of it? Phone a 1-800 number and ask what to do with them? Print them out on paper and mail them to a government agency that helps API clients find their next steps?

只返回完整的URI,所有的时间。提供给客户的ID应始终是URI。 - 它的东西唯一标识该资源中的问题,可以被用于检索,更新或删除问题

Just return the full URI, all the time. The ID given to the client should always be the URI - it's something which uniquely identifies the resource in question and can be used to retrieve, update or remove it.