Bits and Bytes: Forget Parse, Use Azure Mobile Services to Create an API for your Mobile App or Website
When you are building a mobile app or a website mostly likely you are going to need some type of data repository. This can be either files, video or in the form of a “database”. In order to access these repositories you need some sort of access mechanism. Sometimes it is a library or SDK others it is a connection to the database. However, with a mobile app or even websites that are distributed the connection to these repositories can be tricky. You need to create some sort of endpoint for these. Back in the day these were called Web Services now they are called API or Web API’s. Creating them can be time consuming as well. You have to create all of the routines needed to get and put data. You will need to create authentication mechanisms to make sure the proper user is getting and putting data. All in all this could be very time consuming.
If you want to use the new method of Azure App Services, here is a video as well.
First off, make sure you sign up for your Azure account before we begin.
Create Mobile Service
- Login to the Classic Azure Portal. Click on NEW -> MOBILE SERVICE -> CREATE
- Enter a url for your clients to access the service.
- Choose eiher an existing SQL Server or Create a New SQL Server (this is used to host your database).
Create Your Data Table(s)
- Click on the Mobile Service name you just created.
- In the navigation tab, select DATA.
- On the bottom of the screen, click CREATE and choose a table name. You can also modify permissions if needed.
Modify Your Schema
- Click on the table name you just created and select COLUMN from the navigation tab.
- On the bottom of the screen, click ADD COLUMN and add as needed.
- You can connect to the Database you just created by using a SQL client tool and your connection string.
- To find your connection string click on DB in the left nav, find your Database name and you will see your connection string.
- Windows: can use SQL Management Tools or Cloud Explorer (within Visual Studio), or Mac: SQLPro for MSSQL or Mac SQL Studio
- FYI: if you are connecting to the SQL server you will have to add your ip address to the server firewall.
Access Your Table API
- Automatically you will get a CRUD (create, read, update, delete) API created for you.
- Click on the table and then click on SCRIPT in the navigation tab
- There will be 4 scripts that you can modify if needed.
- FYI: if you name your object and properties in your code, then no need to change anything in the api unless you need specific business logic
- Your endpoint will be: https://MOBILE SERVICE NAME.azure-mobile.net/tables/TABLE NAME
Create A Custom API
- From our Mobile Services page, click on the navigation tab API.
- Click CREATE -> and provide your custom API with a name.
- Here you can build custom logic to query multiple tables or perform some other routine.
- Your endpoint will be: https://MOBILE SERVICE NAME.azure-mobile.net/api/API NAME
View Errors and Logs
- From our Mobile Services page, click on the navigation tab LOGS.
- All logs will be there.