问题描述
我需要为客户端提供HTTP API,以一组记录的形式推送大量数据.我的第一个想法是提供一组三个呼叫,例如:
I need to provide an HTTP API for clients to push massive data, in the shape of a set of records.My first idea was to provide a set of three calls, like:
- "BeginPushData"(无参数,返回ID)
- "PushSomeData"(参数:ID,数据子集,无返回值)
- "EndPushData"(参数:id)
第一个调用应用于初始化一些临时数据结构并为用户提供标识符,以便后续调用可以引用它,并且多个用户的数据也不会混乱.在所有数据都发送到服务器之前,应根据需要多次调用第二个调用.最后,调用最后一个调用,客户端确认所有数据都已推送,因此服务器可以处理刚刚存储的所有临时数据.
The first call should be used to initialize some temporary data structure and give the user an identifier, so that subsequent calls can refer to it and data from multiple users don't mess up. The second call should be invoked as many times as needed, until all data is sent to the server. Finally, invoking the last call, the client confirms that all data has been pushed, so the server can process all the temporary data just stored.
通常,遵循REST原则被认为是一种好习惯,但是这种上传大数据的策略显然违反了无状态的REST原则.因此,我正在寻找一种更好的替代方法来完成这项工作.对知名模式的引用将不胜感激!
In general, it's considered a good practice to conform to REST principles, but this strategy of uploading large data clearly violates the REST principle of being stateless. For this reason, I'm looking for some better alternative way of doing the job. References to well-known patterns would be appreciated!
推荐答案
该设计对我来说听起来很合理,我认为它符合无状态.
The design sounds perfectly reasonable to me, and I think it conforms to the ReSTful principle of Statelessness as well.
从初始推送返回的id
满足了该要求. id
由应用程序维护和重用;因此服务器上没有存储会话状态,只有资源状态.
That requirement is satisfied by the id
returned from the initial push. The id
is maintained and reused by the application; so there is no session state stored on the server, only resource state.
这篇关于如何设计HTTP API推送海量数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!