从浏览器应用程序发布数据而无需编写自己的服务器 [英] Publish data from browser app without writing my own server

查看:145
本文介绍了从浏览器应用程序发布数据而无需编写自己的服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要用户能够将单页浏览器应用程序(SPA)中的数据发布给我,但我不能将服务器端代码放在主机上。

I need users to be able to post data from a single page browser application (SPA) to me, but I can't put server-side code on the host.

我是否可以使用这项服务?我查看了 Amazon SQS (简单队列服务),但我无法从内部调用他们的REST API浏览器由于交叉来源政策

Is there a web service that I can use for this? I looked at Amazon SQS (simple queue service) but I can't call their REST APIs from within the browser due to cross origin policy.

我现在更喜欢开发而不是稳健性,所以即使只是收到一封电子邮件也没关系。我不确定该网站是否会流行起来。如果是,那么我将开发一个服务器端组件并移动主机。

I favour ease of development over robustness right now, so even just receiving an email would be fine. I'm not sure that the site is even going to catch on. If it does, then I'll develop a server-side component and move hosts.

推荐答案

不仅有Web服务,但是现在有一些强大的系统可以为应用程序提供一种服务器端逻辑的方法。它们被称为BaaS或后端即服务提供商,通常为您的前端应用程序提供一些支柱。

Not only there are Web Services, but nowadays there are robust systems that provide a way to server-side some logic on your applications. They are called BaaS or Backend as a Service providers, usually to provide some backbone to your front end applications.

虽然它们有多种用途,但我会在我看来列出最常见的:

Although they have multiple uses, I'm going to list the most common in my opinion:


  • 对于移动应用程序 - 您可以使用标准平台为您的应用程序存储逻辑和数据,而无需为您编写的每个设备学习API。

  • For mobile applications - Instead of having to learn an API for each device you code to, you can use an standard platform to store logic and data for your application.

用于原型设计 - 如果您想创建一个光滑的应用程序,但您不想编写所有后端逻辑无数据处理代表的所有操作和系统管理 - 通过BaaS提供商,您只需要良好的前端技能来编写您可以想象的最简单的CRUD应用程序。有些BaaS甚至允许您绑定一些 Reduce算法来调用您的API执行。

For prototyping - If you want to create a slick application, but you don't want to code all the backend logic for the data -less dealing with all the operations and system administration that represents-, through a BaaS provider you only need good Front End skills to code the simplest CRUD applications you can imagine. Some BaaS even allow you to bind some Reduce algorithms to calls your perform to their API.

对于Web应用程序 - 当PaaS(平台即服务)为了避免系统管理和操作的麻烦而来到镇上以减轻Backend End开发人员的工作,后端发生同样的事情只是逻辑。有许多克隆可以展示这种策略的真正威力。

For web applications - When PaaS (Platform as a Service) came to town to ease the job for Backend End developers in order to avoid the hassle of System Administration and Operations, it was just logic that the same was going to happen to the Backend. There are many clones that showcase the real power of this strategy.

这一切都很神奇,但我还没有提到它们中的任何一个。我将列出我最了解并实际用于项目的那些。可能有很多,但据我所知,这个已经满足了我的大部分新闻,无论是以前提到过的任何新闻。

All of this is amazing, but I have yet to mention any of them. I'm going to list the ones that I know the most and have actually used in projects. There are probably many, but as far as I know, this one have satisfied most of my news, whether it's any of the previously ones mentioned.

Parse最出色的功能针对移动设备;然而,现在Parse包含了大量的API,允许您将其用作Javascript,Android甚至Windows 8应用程序的完整功能后端服务(Windows 8 SDK

Parse's most outstanding features target mobile devices; however, nowadays Parse contains an incredible amount of API's that allows you to use it as full feature backend service for Javascript, Android and even Windows 8 applications (Windows 8 SDK was introduced a few months ago this year).

Parse代码如何在Javascript中查找?

Parse通过类和对象工作(不是很漂亮吗?),所以首先创建一个特定的类(可以通过Javascript,REST甚至数据浏览器管理器完成),然后将对象添加到特定的类中。

Parse works through classes and objects (ain't that beautiful?), so you first create a specific class (can be done through Javascript, REST or even the Data Browser manager) and then you add objects to specific classes.

首先,添加Parse作为javascript中的脚本标记:

First, add up Parse as a script tag in javascript:

<script type="text/javascript" src="http://www.parsecdn.com/js/parse-1.1.15.min.js"></script>

然后,通过给定的应用程序ID和Javascript密钥,初始化Parse。

Then, through a given Application ID and a Javascript Key, initialize Parse.

Parse.initialize("APPLICATION_ID", "JAVASCRIPT_KEY");

从那里开始,它是所有对象操作

From there, it's all object manipulation

var Person = Parse.Object.extend("Person"); //Person is a class  *cof* uppercase *cof* 
var personObject = new Person();
  personObject.save({name: "John"}, {
  success: function(object) {
    console.log("The object with the data "+ JSON.stringify(object) + " was saved successfully.");
  },
  error: function(model, error) {
    console.log("There was an error! The following model and error object were provided by the Server");
    console.log(model);
    console.log(error);
  }
});

身份验证和安全性如何?

Parse有一个基于用户的身份验证系统,它几乎允许您存储可以操作数据的用户群。如果使用用户信息映射数据,则可以确保只有给定用户才能操作特定数据。另外,在Parse应用程序的设置中,您可以指定不允许任何客户端创建类,以确保执行必要的调用。

Parse has a User based authentication system, which pretty much allows you to store a base of users that can manipulate the data. If map the data with User information, you can ensure that only a given user can manipulate specific data. Plus, in the settings of your Parse application, you can specify that no clients are allowed to create classes, to ensure innecesary calls are performed.

你真的吗?在网络应用程序中使用?

是的,它是我保留中等保真度的工具原型

Yes, it was my tool of choice for a medium fidelity prototype.

Firebase的主要功能是能够为您的应用程序提供实时,而不会有任何麻烦。您不需要 MeteorJS 服务器即可将推送通知带入您的软件。如果您了解Javascript,那么您可以将实时魔术带给您的用户。

Firebase's main feature is the ability to provide Real Time to your application without all the hassle. You don't need a MeteorJS server in order to bring Push Notifications to your software. If you know Javascript, you are half way through to bring Real Time magic to your users.

Firebase在Javascript中的外观如何?

Firebase以REST方式工作,我认为他们在构建 REST的荣耀。举个好例子,看一下Firebase中的以下资源结构:

Firebase works in a REST fashion, and I think they do an amazing job structuring the Glory of REST. As a good example, look at the following Resource structure in Firebase:

https://SampleChat.firebaseIO-demo.com/users/fred/name/first

你不需要成为一名火箭科学家才能知道你检索用户Fred的第一个名字,给出至少一个 - 通常应该有一个UUID而不是一个名字,但是嘿,这是一个例子,让我休息一下 - 。

You don't need to be a rocket scientist to know that you are retrieve the first name of the user "Fred", giving there's at least one -usually there should be a UUID instead of a name, but hey, it's an example, give me a break-.

为了开始使用Firebase,与Parse一样,添加他们的CDN Javascript

In order to start using Firebase, as with Parse, add up their CDN Javascript

<script type='text/javascript' src='https://cdn.firebase.com/v0/firebase.js'></script>

现在,创建一个允许您使用Firebase API的参考对象

Now, create a reference object that will allow you to consume the Firebase API

var myRootRef = new Firebase('https://myprojectname.firebaseIO-demo.com/');

从那里,你可以创建一堆整洁的应用程序。

From there, you can create a bunch of neat applications.

var USERS_LOCATION = 'https://SampleChat.firebaseIO-demo.com/users';
var userId = "Fred"; // Username

var usersRef = new Firebase(USERS_LOCATION);
  usersRef.child(userId).once('value', function(snapshot) {
    var exists = (snapshot.val() !== null);
    if (exists) {
        console.log("Username "+userId+" is part of our database");
    } else {
        console.log("We have no register of the username "+userId);
    }
  });

身份验证和安全性如何?

你很幸运!大约两周前,Firebase 发布了他们的安全API !我还没有去探索它,但我确信它填补了大部分空白,让随机人员可以根据自己的目的使用你的参考。

You are in luck! Firebase released their Security API about two weeks ago! I have yet to explore it, but I'm sure it fills most of the gaps that allowed random people to use your reference to their own purpose.

你真的在网络应用程序中使用过吗?

Eeehm ......好吧,不。我在 Chrome扩展程序中使用它!它仍在进行中,但它将在Chrome扩展程序中进行实时聊天。那不是很酷吗?精细。我觉得很酷。无论如何,您可以在示例页面中浏览Firebase的更多精彩示例。

Eeehm... ok, no. I used it in a Chrome Extension! It's still in process but it's going to be a Real Time chat inside a Chrome Extension. Ain't that cool? Fine. I find it cool. Anyway, you can browse more awesome examples for Firebase in their examples page.

这些服务的神奇之处是什么?如果您阅读依赖注入模拟对象测试,您可以通过REST Web服务提供商完全替换所有这些服务。

What's the magic of these services? If you read your Dependency Injection and Mock Object Testing, at some point you can completely replace all of those services for your own through a REST Web Service provider.

由于这些服务是为了在任何应用程序中使用而创建的,因此它们已准备就绪。如前所述,我已成功使用多个域中的两个域而没有任何问题(我甚至尝试在Chrome扩展中使用Firebase,我相信我很快就会成功)。

Since these services were created to be used inside any application, they are CORS ready. As stated before, I have successfully used both of them from multiple domains without any issue (I'm even trying to use Firebase in a Chrome Extension, and I'm sure I will succeed soon).

Parse和Firebase都有数据浏览器管理器,这意味着您可以通过简单的Web浏览器查看您正在操作的数据。作为最终的免责声明,除了 James Taplin (Firebase Co-)之外,我与任何其他服务都没有任何关系。创始人)真是太棒了,可以给我一些Beta访问Firebase。

Both Parse and Firebase have Data Browser managers, which means that you can see the data you are manipulating through a simple web browser. As a final disclaimer, I have no relationship with any of those services other than the face that James Taplin (Firebase Co-founder) was amazing enough to lend me some Beta access to Firebase.

这篇关于从浏览器应用程序发布数据而无需编写自己的服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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