azure架构_使用Azure移动服务和动态架构在Hackathon上快速迭代

本文介绍了如何在Azure上快速创建和迭代移动服务,包括设置后端数据库、创建表、插入和检索数据。作者通过cURL、Fiddler和Postman展示了将JSON数据发布到移动服务的不同方法,并强调了Azure移动服务在快速开发中的作用。
摘要由CSDN通过智能技术生成
azure架构

azure架构

Photo from Digital Undivided's Facebook

This last weekend I was in New York presenting at FOCUS100. I also was a mentor for the 24 hour mobile hackathon along with Tara Walker. The attendees were trying to create a mobile app (responsive site, or a native app, it didn't matter) in a single day (we were up all night.) A few of the teams didn't have any back-end experience, but had deep HTML and JavaScript experience. Rather than having them hardcode data a few ended up using Azure Mobile Services (which isn't the best name, but it's something.)

上个周末我在纽约参加FOCUS100演讲。 我也是Tara Walker的24小时移动黑客马拉松的指导者。 与会者试图在一天之内(我们整夜忙碌起来)创建一个移动应用程序(响应式网站或本机应用程序,这无关紧要)。一些团队没有任何后端经验,但具有丰富HTML和JavaScript经验。 最终他们没有使用硬编码数据,而是使用Azure移动服务(这不是最好的名称,而是某些东西)。

I call it a backend in a box. Rather than creating your own RESTful service with CRUD (Create, Read, Update, Delete) to return JSON stored in a database, you show Mobile Services what your data should be shaped like and lets you query it dynamically. So it's an abstraction over the boring stuff. You can add custom APIs and fully edit all operations later, but it gets you 80% of what you want for 20% of the time. Later you spend 80% of your time doing all your custom stuff; it's a great accelerator. It also abstracts away social identity logins (Facebook, Twitter, Google, Microsoft ID) as well as mobile push notifications.

我称其为“后端”。 与其使用CRUD(创建,读取,更新,删除)创建自己的RESTful服务以返回存储在数据库中的JSON,而是向Mobile Services展示数据的形状,然后让您动态查询。 因此,它是对无聊内容的抽象。 您可以添加自定义API并在以后完全编辑所有操作,但是在20%的时间里可以得到80%的所需资源。 后来,您花费了80%的时间来做所有自定义的工作; 这是一个很棒的加速器。 它还提取了社交身份登录名(Facebook,Twitter,Google,Microsoft ID)以及移动推送通知。

Even though it's called Azure Mobile Services, it could also be called "Backend in a Box" or "Azure Backend Accelerator" but somehow those aren't really good names either. ;)

即使它被称为Azure移动服务,它也可以被称为“盒子中的后端”或“ Azure后端加速器”,但是以某种方式,它们也不是很好的名字。 ;)

Here's how we iterated very quickly with one project. There's some tricks that we discovered to make things easier and more obvious. I'm pushing all the things we/I learned back into the Mobile Services team as they iterate quickly and are always improving the service.

这是我们如何快速地迭代一个项目的方法。 我们发现了一些使事情变得更加容易和显而易见的技巧。 我将我们/我学到的所有内容都推回移动服务团队,因为它们快速迭代并且始终在改善服务。

Azure移动服务的初始迭代 (Initial Iterations with Azure Mobile Services)

First, let's assume you've signed for a free trial at Azure.com. You get $200 in credits (which is enough to run two VMs full time or dozens of standard sites on a single VM for a month, as well as 10 free websites, and 10 free mobile services).

首先,假设您已经在Azure.com上签署了免费试用版。 您将获得$ 200的赠金(足以在一个VM上运行两个月的全时虚拟机或数十个标准站点,以及10个免费网站和10个免费移动服务)。

You might also install the Azure CLI (Command Line Interface) via NPM as in "npm install azure-cli --g" then run "azure account download" then "azure account import" to associate your subscription's certs with the command line.

您也可以通过NPM安装Azure CLI(命令行界面),如“ npm install azure-cli --g”中所示,然后运行“ azure帐户下载”然后“ azure帐户导入”以将订阅的证书与命令行相关联。

NOTE: If you are a command line person you can do most everything with the CLI. You can "azure mobile create 'servicename'" or "azure mobile table create" as well as "azure mobile data read" and on and on. We used the HTML5 Portal at the hackathon because it was easier for newbies to visualize.

注意:如果您是命令行用户,则可以使用CLI进行大多数操作。 您可以“打开” azure mobile创建“ servicename”或“ azure mobile table创建”以及“读取azure mobile数据”。 我们在黑客马拉松上使用了HTML5 Portal,因为它使新手更容易可视化。

From the Portal, make a Mobile Service:

在门户上,进行移动服务:

You have no mobile services

Make a mobile service:

进行移动服务:

Making a mobile service

As an FYI, here's doing the same thing at the command line:

仅供参考,在命令行执行以下操作:

c:\>azure mobile create
info: Executing command mobile create
Mobile service name: hanselmanmobile
SQL administrator user name: focus100
SQL administrator password: ********
Confirm password: ********
+ Creating mobile service
info: Overall application state: Healthy
info: Mobile service (hanselmanmobile) state: ProvisionConfigured
info: SQL database (hanselmanmobile_db) state: Provisioned
info: SQL server (aq8l9z9gcb) state: ProvisionConfigured
info: mobile create command OK

Then I can create a Table in my new database. There's several levels of permissions can set, like auth'ed users, or accessible only with the app key. To speed up initial development, I'm setting it to Everyone. Then I'll ratchet up security as the schema starts to gel.

然后,我可以在新数据库中创建一个表。 可以设置多个级别的权限,例如已通过身份验证的用户,或者只能使用应用程序密钥进行访问。 为了加快初始开发速度,我将其设置为“所有人”。 然后,随着模式开始发展,我将增强安全性。

Creating a new table

Here's the same thing at the command line:

在命令行中有相同的内容:

c:\>azure mobile table create hanselmanmobile widgets
info: Executing command mobile table create
+ Creating table
info: mobile table create command OK

I could set the permissions at create time with the command line as well, or update permissions after the fact:

我也可以在创建时通过命令行设置权限,或者在事实发生后更新权限:

c:\>azure mobile table update hanselmanmobile widgets -p read=public,insert=public,delete=public,update=public
info: Executing command mobile table update
+ Updating permissions
info: Updated permissions
info: mobile table update command OK

My endpoint is now http://hanselmanmobile.azure-mobile.net/tables/widgets. (I could have lots of tables, of course.)

我的端点现在是http://hanselmanmobile.azure-mobile.net/tables/widgets 。 (我当然可以有很多桌子。)

How do I get data in there and how do I tell the system what the data looks like? Since JSON is the format Mobile Services uses on the wire, you POST JSON at the service endpoint and it'll store that document.

我如何在其中获取数据,如何告诉系统数据是什么样的? 由于JSON是移动服务在网络上使用的格式,因此您可以在服务终结点上发布JSON,它将存储该文档。

通过多种方式将数据发布到移动服务 (Posting Data to Mobile Services in Multiple Ways)

Some examples for Mobile Services have you/me/developers write an HTML page with JavaScript and run that to POST initial data. I, and the folks at the hackathon, preferred to get the data shape close while the UI folks did their mockups in parallel. Most attendees were familiar with cURL and wanted to use that.

移动服务的一些示例让您/我/开发人员使用JavaScript编写HTML页面并运行该页面以发布初始数据。 我和hackathon的人们更喜欢使数据形状更接近,而UI人们则并行进行其模型制作。 大多数与会者都熟悉cURL,并希望使用它。

Here's three ways to POST data to the new service.

这是将数据发布到新服务的三种方法。

Note that:

注意:

  • The data must be valid JSON.

    数据必须是有效的JSON

  • You must include a Content-Type: application/json header or you'll get an HTTP 400 that says "invalid JSON," even though it may be the missing header.

    您必须包括一个Content-Type:application / json标头,否则您将获得一个HTTP 400,该标头显示“无效JSON”,即使它可能是缺少的标头。
  • A successful record creation will return an HTTP 201 CREATED.

    成功创建记录将返回HTTP 201 CREATED。
通过带有cURL的命令行将JSON发布到移动服务 (Posting JSON to a Mobile Service via Command line with cURL)

I like cURL for GETs, but for POSTing JSON it's complex and a hassle to encode the quotes and double-quotes in JSON correctly. Instead, I POST from a file. Put your JSON exactly as you want it in a text file, then:

我喜欢将cU​​RL用于GET,但是对于JSON的发布来说,它很复杂,而且很难在JSON中正确编码引号和双引号。 相反,我从文件发布。 将JSON完全按照需要放入文本文件中,然后:

c:\>curl -v -X POST -H "Content-Type: application/json" -d @topost.txt http://hanselmanmobile.azure-mobile.net/tables/widgets 

Doing the HTTP POST from a file removes a whole pile of issues. Also, use -v for verbose for ease of debugging.

从文件执行HTTP POST删除的问题一大堆。 另外,使用-v表示详细信息以便于调试。

使用Fiddler将JSON发布到移动服务 (Posting JSON to a Mobile Service with Fiddler)

From my PC using Fiddler I can compose new JSON to POST like this:

在我的电脑上,使用Fiddler,可以像这样将新的JSON编写为POST:

POSTING with Fiddler

And note the HTTP 201 CREATED result:

并注意HTTP 201 CREATED结果:

HTTP 201 CREATED
使用Postman将JSON发布到移动服务 (Posting JSON to a Mobile Service with Postman)

If you're using Google Chrome, you can get the Postman App (it's a REST debugger/Tivo for Chrome) or the REST Console and also POST and GET to your heart's content. Again, make sure to get the Content-Type set.

如果您使用的是Google Chrome浏览器,则可以获取Postman应用程序(这是用于Chrome的REST调试器/ Tivo)或REST控制台,也可以进行发布和获取内容。 同样,请确保获取Content-Type集。

POSTing to an Azure Mobile Service with POSTMAN

Once the data is in the table, I can access it with a simple HTTP GET (in a browser or whatever) as well as via the Azure Command Line Tool or via cURL:

将数据放入表格后,我可以使用简单的HTTP GET(在浏览器中或其他方式)以及通过Azure命令行工具或cURL来访问数据:

c:\>azure mobile data read hanselmanmobile widgets
info: Executing command mobile data read
data: id name price date_available
data: -- -------------- ----- -------------------------
data: 1 Ethernet Cable 5.99 2013-04-12T20:44:55+00:00
info: mobile data read command OK

c:\>curl --header accept:application/json http://hanselmanmobile.azure-mobile.net/tables/widgets
[{"id":1,"name":"Ethernet Cable","price":"5.99","date_available":"2013-04-12T20:44:55.000Z"}]

Of course, I can also see the data in the Portal:

当然,我也可以在门户网站中查看数据:

Data in the Mobile Service

If I don't like the shape of this table, I can drop the table and recreate. I can also call "azure mobile data truncate" from the command line. I can delete an individual column and re-POST, or, if I'm just adding a column, I can post differently shaped data. This is the "dynamic schema" setting. When I get everything the way I want and I'm done iterating, I turn dynamic schema off and freeze the schema.

如果我不喜欢这张桌子的形状,可以放下桌子并重新创建。 我也可以从命令行调用“ azure移动数据截断”。 我可以删除单个列并重新发布,或者,如果我只是添加一列,则可以发布形状不同的数据。 这是“动态架构”设置。 当我以自己想要的方式获得所有内容并完成迭代时,我关闭了动态模式并冻结了该模式。

Azure Mobile Services Dynamic Schema

Mobile Services works great for getting a back end database and CRUD services up FAST. At this point, we were able to hook up HTML and JavaScript on the front-end and start pulling in live data quickly.

移动服务非常适合使后端数据库和CRUD服务更快速地运行。 至此,我们已经能够在前端连接HTML和JavaScript并开始快速提取实时数据

Later I'm going to learn about adding custom APIs, social logins, and push notifications as they'll be useful for future hackathons.

稍后,我将学习有关添加自定义API,社交登录和推送通知的信息,因为它们对于将来的黑客马拉松很有用。

翻译自: https://www.hanselman.com/blog/iterating-quickly-at-a-hackathon-with-azure-mobile-services-and-dynamic-schema

azure架构

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值