This tutorial shows you how to add a cloud-based backend service to an HTML app using Azure Mobile Services. In this tutorial, you will create both a new mobile service and a simple To do list app that stores app data in the new mobile service. You can view the following video version of this tutorial.
A screenshot from the completed app is below:
Completing this tutorial is a prerequisite for all other Mobile Services tutorials for HTML apps. For a PhoneGap/Cordova app, see the the PhoneGap/Cordova version of this tutorial.
The following are required to complete this tutorial:
You must have one of the following web servers running on your local computer:
You can use any web server to host the app, but these are the web servers that are supported by the downloaded scripts.
A web browser that supports HTML5.
An Azure account. If you don't have an account, you can create a free trial account in just a couple of minutes. For details, see Azure Free Trial.
Follow these steps to create a new mobile service.
Log into the Management Portal. At the bottom of the navigation pane, click +NEW. Expand Compute and Mobile Service, then click Create.
This displays the Create a Mobile Service dialog.
This displays the Specify database settings page.
As part of this tutorial, you create a new SQL Database instance and server. You can reuse this new database and administer it as you would any other SQL Database instance. If you already have a database in the same region as the new mobile service, you can instead choose Use existing Database and then select that database. The use of a database in a different region is not recommended because of additional bandwidth costs and higher latencies.
In Name, type the name of the new database, then type Login name, which is the administrator login name for the new SQL Database server, type and confirm the password, and click the check button to complete the process.
You have now created a new mobile service that can be used by your mobile apps.
Once you have created your mobile service, you can follow an easy quickstart in the Management Portal to either create a new app or modify an existing app to connect to your mobile service.
In this section you will create a new HTML app that is connected to your mobile service.
In the Management Portal, click Mobile Services, and then click the mobile service that you just created.
In the quickstart tab, click Windows under Choose platform and expand Create a new HTML app.
This displays the three easy steps to create and host an HTML app connected to your mobile service.
Click Create TodoItems table to create a table to store app data.
Under Download and run your app, click Download.
This downloads the website files for the sample To do list application that is connected to your mobile service. Save the compressed file to your local computer, and make a note of where you save it.
In the Configure tab, verify that
localhost is already listed in the Allow requests from host names list under Cross-Origin Resource Sharing (CORS). If it's not, type
localhost in the Host name field and then click Save.
If you deploy the quickstart app to a web server other than localhost, you must add the host name of the web server to the Allow requests from host names list. For more information, see Cross-origin resource sharing.
The final stage of this tutorial is to host and run your new app on your local computer.
Browse to the location where you saved the compressed project files, expand the files on your computer, and launch one of the following command files from the server subfolder.
On a Windows computer, type
R when PowerShell asks you to confirm that you want to run the script. Your web browser might warn you to not run the script because it was downloaded from the internet. When this happens, you must request that the browser proceed to load the script.
This starts a web server on your local computer to host the new app.
Open the URL http://localhost:8000/ in a web browser to start the app.
In the app, type meaningful text, such as Complete the tutorial, in Enter new task, and then click Add.
This sends a POST request to the new mobile service hosted in Azure. Data from the request is inserted into the TodoItem table. Items stored in the table are returned by the mobile service, and the data is displayed in the second column in the app.
Back in the Management Portal, click the Data tab and then click the TodoItems table.
This lets you browse the data inserted by the app into the table.
Now that you have completed the quickstart, learn how to perform additional important tasks in Mobile Services:
Get started with data
Learn more about storing and querying data using Mobile Services.
Call a custom API from an HTML application
Connect your HTML application with a custom API hosted on Mobile Services.
Get started with authentication
Learn how to authenticate users of your app with an identity provider.