The API App tools in Visual Studio make it easy to generate C# code that calls to your Azure API Apps from desktop, store, and mobile apps.
-
In Visual Studio, open the solution that contains the API app from the Create API app topic.
-
From Solution Explorer, right-click the solution and select the Add > New Project.
-
In the Add New Project dialog, perform the following steps:
-
Right-click the newly created console application project and select Add > Azure API App Client.
-
In the Add Microsoft Azure API App Client dialog, perform the following steps:
-
Select the Download option.
-
From the drop-down list, select the API app that you created earlier.
-
Click OK.
The wizard will download the API metadata file and generate a typed interface for invoking the API App.
Once code generation is complete, you'll see a new folder in Solution Explorer, with the name of the API app. This folder contains the code that implements the client and data models.
-
-
Open the Program.cs file from the project root and replace the Main method with the following code:
static void Main(string[] args) { var client = new ContactsList(); // Send GET request. var contacts = client.Contacts.Get(); foreach (var c in contacts) { Console.WriteLine("{0}: {1} {2}", c.Id, c.Name, c.EmailAddress); } // Send POST request. client.Contacts.Post(new Models.Contact { EmailAddress = "[email protected]", Name = "Loretta Kahn", Id = 4 }); Console.WriteLine("Finished"); Console.ReadLine(); }
Once the API app has been coded, it's time to test the code.