MVC 风格的应用程序架构迎合 API [英] MVC style application architecture catering to API

查看:23
本文介绍了MVC 风格的应用程序架构迎合 API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个社区"风格的网站,既是为了乐趣,也是为了利润,虽然它的美学元素很好地呈现出来,但由于以下原因,我还没有认真研究应用程序逻辑我的方法不确定.

I'm working on a "community" style website, both for fun and profit, and while the aesthetic element of it is coming along nicely, I haven't yet sunk my teeth into working out the application logic for reasons of unsureness in my approach.

我正在创建一个 PHP 驱动的 MVC 样式框架,我希望可以重用其中的组件,但是我注意到许多现有的 MVC 框架使用一种约定优于配置"来加快整个过程.我打算运行的一些查询比 SELECT * FROM entity_name 稍微复杂一些.

I'm creating an PHP powered MVC style framework which I can hopefully reuse components of, however I've noticed that many existing MVC frameworks use a sort of "convention over configuration" to expedite the whole process. Some queries I intend to run are a little more complicated than SELECT * FROM entity_name.

我想分层设计应用程序,以便可以对服务器进行 API 调用.我想,与其将所有事情都做两次,不如在这一层之上构建我的站点控制器,以便一切都遵循标准.这将允许 Ajax 调用、远程 Web 应用程序调用等遵循与文档 Web 请求相同的请求规范化和响应路线.

I want to design the application in layers, so that API calls can be made to the server. I figured instead of doing everything twice, I would build my site controllers on top of this layer, so that everything follows a standard. This will allow Ajax calls, remote web application calls, etc., to follow the same route of request normalization and response as document web requests.

无论如何,也许其中大部分是不必要的细节,但谁能对这种性质的 API 分层 MVC 架构有所了解?由于 API 级别(模型层)是最终读取/写入数据的地方,我是想在此级别合并身份验证,还是将其抽象为更高级别并将其作为入口点?还有哪些我没有提到的其他注意事项?

Anyways, perhaps much of that is unnecessary detail, but can anyone shed some light on API layered MVC architectures of this nature? Since the API level (the model layer) is where data is ultimately read/written, would I want to incorporate authentication at this level, or abstract it to a higher level and make that the entry point? What other considerations should I make that I haven't mentioned?

我知道我还有很多阅读要做,因此非常欢迎任何有关阅读材料的建议或个人经验的建议.提前致谢.

I know I still have much reading to do, so any suggestions for reading materials, or advice from personal experience with this is very welcome. Thanks in advance.

推荐答案

这是一个很好的问题.我认为我最好的选择是尽可能多地使用带有 REST 资源的 SOA 方法如果您的网站获得大量点击,则可能值得将状态变异与状态公开分离,因此第一个可以使用更复杂的 OO 方法,同时另一个可以使用简单的 DTO(以数组的形式)并使用自定义查询从数据库中检索数据.

This is a very good question. I think my best bet would be to use an SOA approach with REST resources as much as possible If your website gets a lot of hits, it might be worth segregating state mutating from state exposing, so the first can use a more complex OO approach whilst the other can use simple DTOs (in the form of arrays) and retrieve the data from the database by using custom queries.

这篇关于MVC 风格的应用程序架构迎合 API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆