简体   繁体   English

HTTP API和调用它的GUI之间的关注点分离

[英]Serparation of concerns between HTTP API and GUI that calls it

I am using an HTTP API. 我正在使用HTTP API。 This is a sort of Home Automation API in a sense. 从某种意义上说,这是一种家庭自动化API。 Really more of a RPC interface but it is expressed as HTTP API. 实际上更多的是RPC接口,但它表示为HTTP API。

It supports PUT: http://server/resource BODY;Json = { 'action': 'value' } 它支持PUT: http:// server / resource BODY; Json = {'action':'value'}

OK. 好。 Now I want to create a GUI (HTTP/CSS in my case but that does not matter for this question). 现在,我想创建一个GUI(在我的情况下为HTTP / CSS,但这对这个问题无关紧要)。 The GUI will have a button to invoke each of these actions. GUI将具有一个按钮来调用这些动作中的每一个。 So the GUI needs: 因此,GUI需要:

  1. A list of valid actions (clearly API responsibility) 有效操作列表(显然是API责任)
  2. The 'value' to PUT for 'ACTION' (API Responsibilty) “操作”(API责任)的PUT的“值”
  3. An icon for each button (??? Who is responsible) 每个按钮的图标(???谁负责)
  4. A Text Label for each button' (??? Who is responsible) 每个按钮的文本标签” (???谁负责)

I don't want to have to compile/rebuild the Gui if the API changes so I want to store the button config in some sort of meta data. 如果API发生更改,我不需要编译/重建Gui,因此我想将按钮配置存储在某种元数据中。

So, the question is; 因此,问题是; to maintain a separation of concerns, whose responsibility is this metadata. 保持关注点分离,其责任就是该元数据。 The API or the GUI. API或GUI。

If I put it in the API then multiple GUI's can GET this metadata and all look similar and will react to changes in the API. 如果我将其放在API中,则多个GUI可以获取此元数据,并且看起来都相似,并且会对API中的更改做出反应。

But, icons and such really feel like GUI data. 但是,图标等确实感觉像GUI数据。

I could really use some help understanding the best practices for how to split these layers and still maintain a good separation of concerns. 我真的可以使用一些帮助来了解有关如何拆分这些层的最佳实践,并仍然保持良好的关注点分离。

Thanks in advance 提前致谢

This will require making a lot of assumptions about your application, but it sure sounds like these are really GUI concerns, and should remain in the GUI. 这将需要对您的应用程序做出许多假设,但是可以肯定,这听起来确实是GUI问题,应该保留在GUI中。 If you start doing things like making the API responsible for the display of the GUI you are no longer creating an API, you are creating a web application. 如果开始执行使API负责GUI显示的工作,那么您将不再创建API,而是在创建Web应用程序。

Now, that being said, your API sounds like it's a little too generic, and maybe wrapping that API in a web application is the right thing to do, but that would be a pretty big deviation from your original question scope. 话虽如此,您的API听起来有点太通用了,也许将API封装在Web应用程序中是正确的做法,但这与您原来的问题范围有很大的出入。

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

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