将 Rails API 和 Rails 应用分开是否有意义? [英] Does it make sense to separate Rails API and Rails app?

查看:20
本文介绍了将 Rails API 和 Rails 应用分开是否有意义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个涉及移动和网络客户端的项目.移动客户端将主要获取内容并发布用户更新,而 Web 客户端主要用于创建内容.因此,Web 客户端和 API 共享许多相同的模型和验证.

I have a project that involves both mobile and web clients. The mobile clients will mainly get content and post user updates, while the web client is mainly for creating content. As such, the web client and API share a lot of the same models and validation.

我正在尝试决定在这种情况下的最佳方法:

I am trying to decide the best approach in this case:

  1. 仅 JSON 的 Rails API + 调用 API 的单独 Rails Web 客户端.
  2. API 和客户端分离的单个 Rails 应用(以某种方式).

就选项 N°1 而言,我的优点是关注点分离,因为我可以在 API 上工作,而其他人则在 Web 客户端上工作.在验证方面,骗局似乎有很多重复的代码.

The pro for me in terms of option N°1 is the separation of concerns, as I can work on the API while someone else do the web client. The con seems to be lots of duplicated code in terms of validation.

N°2 在减少代码重复方面可能更有意义,但如果不止一个人在同一个代码库上工作并且设置解决代码冲突的过程不是我想要做的事情,它会变得混乱这一点是因为我们是一家处于早期阶段的初创公司,想要快速推出一些产品.

N°2 could make more sense in terms of reducing code duplication but it would get messy if more than one person is working on the same code base and setting up a process to resolve code conflicts is not something I want to do at this point since we're an early stage startup and want to get out something quickly.

有什么我遗漏的吗?

推荐答案

最佳实践是将 ONE rails 应用程序用于 API 和 Web 界面

The best practice is use ONE rails application for API and Web Interface

要分离这些部分,只需为 API 创建一个命名空间,就像那里描述的那样 http://collectiveidea.com/blog/archives/2013/06/13/building-awesome-rails-apis-part-1/

To separate those parts, just create a namespace for API like it's described there http://collectiveidea.com/blog/archives/2013/06/13/building-awesome-rails-apis-part-1/

这篇关于将 Rails API 和 Rails 应用分开是否有意义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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