Hell guys I’m here to demonstrate you about how to make your own API using Windows Azure in just 20 mins. Keep following the steps and you will end in by making your own API’s. You can sell it in market for others to use or use it for your own purpose. Before I begin to demonstrate you, I assume you are having an Azure account. If not then I would recommend you to sign up for free on Windows Azure and enjoy free one month trail period. You can click here to sign up for free.
The thing which we are going to learn is quite amazing cause making API’s is considered as one of the most difficult task and a lot of us are not able to make the desired applications cause we don’t have API’s or we are not able to make our own API’s for our services. But from now on, each and everything would be on your tips on How to make your own API using Windows Azure. So let’s start and first login to your Azure Account.
Step 1: Click on NEW that is popping up on the bottom left of your screen.
Step 2: Select Data Services followed by SQL Database then Quick Create. Now give your database a name, select a New SQL database server, select a region and lastly give a login name and password. It would be required in step ahead.
Step 3: After Successful creation of SQL Database now click Manage.
Step 4: After you have click Manage a new Page will open up as shown below. Enter the Username and Password here that you gave in first step and click log on. This step will take few mins to login to the account.
Step 6: Now Click on Design present on bottom left and then click New Table as shown below.
Step 9: Now add values into the row and create 4 to 5 rows. After that click Save.
public class ClassesData
{
public List<Classes> ListofData = new List<Classes>();
}
Step 17: Add a new WebForm to the project and Delete all the text in the WebForm.aspx file except the first line as shown below.
ClassesData data = new ClassesData(); string key = null; protected void Page_Load(object sender, EventArgs e) { key = Request["key"]; if (key == "yourapikey") { Load(); } else { data.ListofData = null; Response.Write(JsonConvert.SerializeObject(data)); } } public void Load() { SqlConnection connection = new SqlConnection(Connection.ConnectionString); try { connection.Open(); SqlCommand readcommand = new SqlCommand("SELECT * FROM Sample", connection); SqlDataReader reader = readcommand.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { data.ListofData.Add(new Classes(Convert.ToInt32(reader["ID"].ToString()), reader["name"].ToString(), reader["age"].ToString())); } Response.Write(JsonConvert.SerializeObject(data)); } else { data.ListofData = null; Response.Write(JsonConvert.SerializeObject(data)); } reader.Close(); connection.Close(); } catch (Exception ex) { data.ListofData = null; Response.Write(JsonConvert.SerializeObject(data)); } }
Step 19: Something like that would happen as shown below.
Isn’t it amazing you can now make API’s for your own services or you can make API’s for different firms in no time and charge them as much as you want cause making API’s is one of the most difficult task. Larger Organizations have separate departments who just work on their API’s.