一个单独的REST API后端的优势? [英] Advantages of a separate REST backend API?

查看:168
本文介绍了一个单独的REST API后端的优势?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

上下文:我是一个初学编程的,自作出一个SPA的希望任教。我已经开始使用JavaScript和jQuery,PHP和MySQL,现在感觉pretty信心与所有。我已经开始与Ember,而我现在从具有PHP API到节点搬走。然后它给我带来了接近流星......我知道我需要使用蒙戈代替,但有一个集成的正面和背面似乎是合理的,并有一定的优势。

Context: I'm a beginner programmer, self taught in the hope of making a SPA. I've started with JavaScript, Jquery, PHP and MySQL, and now feel pretty confident with all. I've started with Ember, and am now moving away from having a PHP API to Node. Which has then brought me closer to Meteor... I'm aware I'll need to use Mongo instead, but having an integrated front and back seems to be sensible and have some advantages.

我的问题是什么是有一个单独的REST API后端(如前preSS),而不是一个集成的前/后(如流星)的优点。

一说弹簧想到的是,我的应用程序将根据平板/ PC,但在今后我会想要一个不同的移动版本,所以我可以使用刚刚使用相同的API。我意识到上述问题与此栈的问题主要关注的问题,但或许犹如一颗流星开发人员可以澄清这是否确实是一个问题。

One that springs to mind is that my app will be tablet/pc based, but in future I'll want a different mobile version, so I'd be able to use just use the same API. I'm conscious that the above question is the main concern with this stack question, but perhaps if a meteor developer could clarify whether this is indeed a concern.

在此先感谢!

推荐答案

流星并没有真正融入前(客户端)和后端(服务器)为你描述。它仍然保持它们作为两个单独的层。流星的美(除了疯狂真棒反应性)的是,它使用JavaScript无处不在,而不是在客户端和服务器上的其他一些语言使用JS,所以你可以使用前部和后端都相同的API。虽然流星确实喜欢让时髦的东西,你写在同一文件中的客户端和服务器code,它仍然需要你区分这两者,和服务器code仍然是在服务器和客户端$ C只存储$ C仍然是服务到客户端。

Meteor doesn't really "integrate" the front (client) and backend (server) as you describe. It still maintains them as two separate layers. The beauty of meteor (aside from the insanely awesome reactivity) is that it uses Javascript everywhere, instead of using JS on the client and some other language on the server, so you can use the same APIs on both the front and backend. Although Meteor does snazzy things like let you write client and server code in the same file, it still requires you to distinguish between the two, and server code is still stored only on the server and client-side code is still served down to the client.

流星还很年轻,但开发商和社区非常活跃,你描述的一切都可以用它在这一点上可以实现。我一直在与流星大约6个月了,到现在也没有让我失望过。我的工作也需要暴露REST API的移动应用程序,这我和流星做得相当成功的消费产品级的应用程序(我刚刚更新使用REST端点从Android设备用户配置文件,看着它变化实时流星应用。太酷了!)。

Meteor is still young, but the developers and community are very active, and everything you described can be achieved with it at this point. I've been working with Meteor for about 6 months now, and it hasn't let me down yet. I'm working on a production-level application that also requires exposing a REST API for consumption in mobile apps, which I'm doing quite successfully with Meteor (I just updated a user profile using a REST endpoint from an Android device and watched it change in the Meteor app in realtime. So cool!).

我是用这个大包,RestStop2,对于流星构建REST API的,但不幸的是德precated,所以我发布了一个更新的版本。检查出来的流星构建REST API的示例。它可通过流星包管理器: https://atmospherejs.com/nimble/restivus

I was using this great package, RestStop2, for building REST APIs in meteor, but it was unfortunately deprecated, so I released an updated version. Check it out for an example of building REST APIs in Meteor. It's available through the Meteor package manager: https://atmospherejs.com/nimble/restivus

因此​​,要回答你的问题,你总是希望在REST API分离到它自己的一层,但是这是完全可能的流星。要清楚,你永远不会从你的流星应用程序内消耗这一REST API。流星采用DDP(非HTTP),让您与您的服务器更加直接连接,所以你做错了什么,如果你从一个流星客户端通过HTTP访问您的流星服务器上的数据。当然,流星,你有能够使用现有的code从你的REST API的优势。

So to answer your question, you always want to separate the REST API into it's own layer, but that is entirely possible with Meteor. To make it clear, you would never consume this REST API from within your Meteor app. Meteor uses DDP (not HTTP), which gives you a much more direct connection with your server, so you're doing something wrong if you're accessing data on your Meteor server from a Meteor client via HTTP. Of course, with Meteor, you have the advantage of being able to use existing code from your REST API.

有一个真正的好写了,解释了一些写在流星REST API的注意事项: HTTP ://www.meteorpedia.com/read/REST_API

There's a really good write-up that explains some of the considerations of writing a REST API in Meteor: http://www.meteorpedia.com/read/REST_API.

这篇关于一个单独的REST API后端的优势?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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