简体   繁体   English

构建REST API-单独的请求

[英]Building REST API - separate requests

I am building an API and am a little unsure whether it would be better to have a request that brings back all information relating to a resource, or just bring back info separately according to tasks that need carrying out. 我正在构建一个API,有点不确定是否最好有一个要求带回与资源有关的所有信息的请求,或者只是根据需要执行的任务单独带回信息。 For example, I have a messages resource and am struggling to decide whether to bring back all message information in one go. 例如,我有一个消息资源,并且正在努力决定是否一次性收回所有消息信息。 OR have a separate request for unread messages, a separate request for a list of messages and another request for a single message. 或对未读消息有单独的请求,对消息列表有单独的请求,对单个消息有另一个请求。

What is the proper way? 正确的方法是什么? I am tempted to keep them all separate but then worrya bout having to do too many requests. 我很想把它们分开,但是然后担心不得不做太多的请求。

Stop worrying and just do . 别担心, 去做

I like to keep things separate in the beginning, and at some point, I realise that request x always followed by request y , so I'll just merge those two. 我喜欢一开始就将它们分开,并且在某个时候,我意识到请求x总是跟在请求y之后 ,所以我将把这两个合并。 You won't know what you'll need until you're working on it... 除非您正在研究它,否则您将不知道需要什么...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM