Introduction
This article is a continuation of my previous writings on Cross Platforms, here I will be dealing with creating mobile apps in Azure with backend and REST API’s.
Creating Mobile Service from Visual Studio 2015
Keep your Visual Studio 2015 running now and click on New Project, move to Cloud and select Mobile Service of Azure.
This will take you to a window where you can select the new project by configuring as per your need.
Click on Cloud - Azure Mobile Service - Name your project. Select the location where you want to save this project and click on OK
You will see another window as shown below.
Azure Mobile services supports only for Web API so let's select Web API, and we need this to be hosted in the cloud, but Microsoft Azure has recently stopped mobile service and to access this we have to work from the Azure Mobile Apps. So let's open a browser and we will move to the Azure portal.
Azure Portal Link - www.portal.azure.com
Click on New - Web + Mobile - Mobile App.
Give the app a name, select the Subscription, Resource Group, App Service Plan/Location with Application Insight here. After it is configured click on create.
And now the Mobile App gets deployed in the Azure portal.
And now that the mobile app, namely the Mobile Service, has been created, move to Visual Studio 2015 and click on Server Explorer. You can find the Resource group and mobile app over there.
Here in the solution explorer you can find the Web API using the entity framework as the data backend, you can find DataObjectsïƒ ToDoItem.cs here.
You can find the base class named Entity Data which is used by the Mobile Services framework. This will help us with the unique ID’s and features, etc.,
You can also find MobileServiceContext or the Database Context which is a entity framework and helps to manages the data in the back end.
It also has TodoItems which has been already set here.
You should also find something called Controllers which is a Web API controller which derives the table controller. This is a REST API which contains code to get data from ToDoItems, post and add new ones, perform changes, or delete an item.
And now you can run this project by selecting Crossplatformx.Backend in Solution Explorer and setting it as a Startup Project.
Now you can run this project by selecting the browser that you need and by just running the project.
Here I will be selecting Internet Explorer and will run the project. And when you build a project you will get an output pane with the status of the project as shown below
Now you can find the output in a Web Browser as shown below
You can click on the Try it Out option to get some help with the Web APIs which will take you to the Help tutorial page as shown below
This displays the Jobs and Todoitem. Let's click on the GET tables/TodoItem, this will display the response information of JSON format. Now let's click on Try this out to check what happens with this GET table.
Click on Send in the below window.
This will display two different IDs for you now as shown below
We can also use tools like Fiddler or any other tool to access this REST API. Now let's close this window, we will move to the Web Browser and select the below URL address.
Existing URL - http//localhost61731/help/Api/GET-tables-TodoItem
Replace with new URL - http//localhost61731/tables/TodoItem
And now we get the same JSON response here, which is a file gets downloaded now and opened in Visual Studio 2015 automatically, so you just hit the REST API and get response from here using Azure Mobile Apps.
Keynotes in Short
- Creating Mobile Apps in Azure.
- About Data Objects in Solution Explorer.
- About Models in Solution Explorer.
- About Controllers in Solution Explorer.
- Build project in Visual Studio 2015.
- Accessing JSON response GET Tables.
- REST API access for Mobile Apps in Azure.