API为核心的网站和放大器;移动应用 [英] API as core for a website & mobile-app

查看:139
本文介绍了API为核心的网站和放大器;移动应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个完整的架构理念不同的问题。我希望有人有很好的经验可以帮助我,因为我是pretty多被陷在所有的可能性。

I have different questions about a full architecture idea. I hope someone with great experience could help me out because I am pretty much getting stuck in all possibilities.

我打算重写一个社区网站。我们的客户希望借助原生移动应用的未来。所以,我需要考虑到这一点。正因为如此,我决定创建一个基于PHP框架Kohana的100%的REST API架构。我已经选择Kohana的,因为这使得没有多少额外的努力很容易结垢的内部API到其他服务器。 (Kohana的威胁内部URL的请求不是HTTP,所以没有在一开始的开销,并且可以扩展一些小code更改HTTP)。

I'm planning to rewrite a community website. Our customer wants to make use of native mobile apps in the future. So I will need to take this into account. Because of this I have decided to create a 100% REST API architecture based on the PHP framework Kohana. I have choosen Kohana because this makes scaling the internal API to a other server very easily without much extra effort. (Kohana threats internal url requests not as HTTP so there isn't much overhead in the beginning and can scale to HTTP with some minor code changes).

起初,API将是私人的,但后来我们不妨把它公开,让更多的服务连接到我们轻松。

At first the API will be private, but later on we might make it public to let more services connect to us easily.

德REST的基本结构如下:

De basic REST structure is as follow:


  1. /猫

  2. /猫/ 1

  3. /猫/ 1 /定制

自定义可能是例如蔡尔兹'。

'custom' could be 'childs' for instance.

也一样:


  1. /广告

  2. /出价

  3. /用户

  4. /横幅


这些是在API完美的实体,因为移动应用肯定会使用所有这些功能。

These are perfect entities for the API because the mobile app will definitely use all this functionality.

因此​​,我们可以得出结论,该网站的核心是REST。所以基本上我想使网站的API的客户就像在今后的本机应用程序。通过这种方式维护似乎更容易。

So we can conclude the core of the website is REST. So basically I want to make the website a client of the API just like the native app in the future. This way maintenance seems much easier.

我担心虽然是事实,那就是远不止此(管理上传的文件,发票,automails开票,automails的广告等)。上传文件需要通过网站的API。这是常见的做法?如果我不这样做,该网站会做上传的逻辑,这使得该网站没有客户端不再和应用程序本身。因此,移动应用程序甚至无法上传和两个API和网站需要知道上传文件夹(重复的逻辑)。

What worries me though is the fact that there is much more than this (managing uploaded files, invoicing, automails for invoicing, automails for ads and so on). Uploading files needs to go through the website to the API. Is this common practice? If I do not do this, the website would do upload logic, which makes the site no client anymore and the app itself. Hence the mobile app can't even upload and both API and website need to know the upload folder (duplicate logic).

我想创建以下模块:


  1. 社区API

  2. 社区网站

阿比似乎是核心然后。但是....怎么样cronjobs等?其实他们不应该是网站的一部分,因为这仅仅是一个客户。我觉得他们应该用模型或API直接交互。所以基本上API变得更像一个门户的核心,我想我需要这样的:

Api seems to be the core then. But.... what about cronjobs etc? Actually they should not be part of the website, as this is just a 'client'. I feel they should interact directly with the model or API. So basically the API gets more like a gateway to the core and thought I need this:


  1. 社区为核心

    • 模式

    • Cronjobs

    • 自动邮件(cronjobs的一部分)

      • 发票等


  • 通过HTTP与核心模型互动


  • 网站

  • 管理

核心cronjobs是一个例外REST结构。它们是可以改变的数据,而不通过该API将唯一的一个。至少这是我的想法,因为他们在核心属于和API是在核心之上。

The core cronjobs are a exception to the REST structure. They are the only one that can change data without going through the api. At least that was my idea because they belong in the core and API is on top of the core.

但是,通过设计,这似乎只是错误的。操纵应该只通过API!

But by design that seems just wrong. Manipulating should only go through the API!

备选:


  1. 社区为核心

    • 模式


  • 通过HTTP与核心模型互动


  • Cronjobs

  • 自动邮件(cronjobs的一部分)

    • 发票等


    • 网站

    • 管理

    这看起来设计更好的给我。

    This look better by design to me.

    主要问题

    1)

    如果cronjobs通过API或核机型操作?

    Should cronjobs manipulate through the API or Core models?

    2)

    我的发票的cronjob需要一个模板pretty当然主要网站的大部分风格。但是,如果我的cronjob是企业或核心的一部分,它不会有我的主要网站的知识。情理之中的事情来解决这个?

    My invoice cronjob needs a template pretty much the style of main website of course. But if my cronjob is part of business or core it won't have knowledge of my main website. What makes sense to solve this?

    3)

    我的网站将使用的胡子作为模板引擎。 (PHP和JavaScript可以解析这些模板)。我想直接使用API​​的Ajax调用,但后来意识到:

    My website will be using mustache as a template engine. (both php and javascript can parse these templates). I thought using the api directly for ajax calls but then realized:

    该网站从API获取数据,格式化时间戳时间(Y-M-D)为模板,然后渲染。如果我让的JavaScript直接调用API,JavaScript的必须具备的逻辑太(格式化)。这是重复的code!感觉就像唯一的解决办法是要求AJAX网站(它调用的API和格式),并返回格式化的JSON。我说得对不对?

    The site gets data from api, formats timestamps to dates (Y-m-d) for the template and then renders. If I let javascript call the api directly, javascript must have logic too (formatting). This is duplicate code! Feels like the only solution is calling the website for ajax (which calls the api and formats) and returns the formatted json. Am I right?

    但是....简单的调用,如删除一个广告可以直接通过API(例如DELETE:/广告/ 1

    But.... simple calls like deleting a ad can go through the api directly (e.g. DELETE: /ads/1

    我收到电话的混合....

    I get a mix of calls....

    此Any更好的解决方案?

    Any better solution for this?

    4)

    总:是我的建筑太复杂?任何替代品,我应该考虑的?

    Overall: Is my architecture too complex? Any alternatives I should consider?

    我很想听听您的意见!

    推荐答案

    在我听说要开发一个Web应用程序的好方法是开发的 API为中心的Web应用程序。问题是,对我来说,如果你对夫妇主要服务于公共API,建立一个API为中心的应用程序时,你失去了在所有发展中公共API的整点。

    Once I've heard that a good way to develop a web application is to develop an API-Centric Web Application. The thing is, to me, if you couple the main service to the public API, building an API-Centric application, you lose the whole point of developing a public API at all.

    这篇关于API为核心的网站和放大器;移动应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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