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

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

问题描述

我有一个涉及移动和Web客户端的项目.移动客户端主要获取内容并发布用户更新,而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的优点是关注点分离,因为我可以在其他人通过Web客户端进行操作时使用API​​.在验证方面,缺点似乎是很多重复的代码.

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创建一个名称空间,如此处所述

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天全站免登陆