This article is now deprecated. SDK usage instructions are now contained in the generated SDK.
See the new APIMATIC docs.
In this article, we will walk you through the generation of the SDK and how to use it.
The following covers the following aspects:
- Setting up the environment
- SDK generation instructions
- SDK installation instructions
- Creating a sample application that uses our SDK
1. Setting up the environment:
Following this tutorial here, a library is already generated, downloaded, and ready for use.
We will be using Visual Studio IDE for C#.
2. SDK generation instructions:
After choosing C# as your code language, as shown in Figure 1, a zipped file will be downloaded. This file contains the code for the APIMATICCalculator library we will be using in our project.
Figure 1: Choosing C# as the language of generation.
3. SDK installation instructions:
In order to use your library, you have to unzip it and build it first.
Extract the unzipped file to a new folder, as shown in Figure 2. Double click on the solution file (.sln) highlighted in Figure 2, to load it on your IDE.
Figure 2: Unzipped library contents.
To build, right click on the project in the solution explorer, and choose Build from the menu, as shown in Figure 3. This step will restore any Nuget packages needed for the project, if they weren't already installed.
Figure 3: Building our library.
The build process generates a portable class library, which can be used like a normal class library. The generated library is compatible with Windows Forms, Windows RT, Windows Phone 8, Silverlight 5, Xamarin iOS, Xamarin Android and Mono.
4. Creating a sample application:
The following section explains how to create a new project (in the same solution) that uses your generated APIMATICCalculator library.
4.1 Starting a new project
On starting a new project, choose New -> Project, from the File menu on the top left.
Figure 4: Creating a new project.
Choose "Console Application", provide a project name and choose "Add to solution" from the drop down menu, as shown in Figure 5. Finally, click "OK".
Figure 5: Adding project it to our solution.
4.2 Adding library reference to your project
In order to use the APIMATICCalculator library in your project, you have to add its reference to your project.
Right click "References" under your project from the solution explorer, and click "Add reference", as shown in Figure 6.
Figure 6: Adding library reference to our project, step 1.
A window will be displayed where you tick on your APIMATICCalculator library to be added and click "OK", as shown in Figure 7.
Figure 7: Adding library reference to our project, step 2.
4.3 Building your project
In order to build this project, from the solution explorer, right click on your project and choose "Build" from the drop-down menu, as shown in Figure 8.
Figure 8: Building project successfully.
You are ready to use the library in your code.
4.4 Using your library in your project:
In order to run our project in the same solution, firstly, we need to set our "myCalculator" project as the start-up project. This ensures that the IDE knows the entry point to your solution. In other words, an entry point is where the IDE finds and runs the main class.
Right-click on your project and choose "set as StartUp Project" form the drop-down menu, as shown in Figure 9.
Figure 9: Setting our project as our StartUp project.
To use the library, you need to instantiate its objects and invoke their methods.
Like any other object, a controller is instantiated by calling its constructor.
To get our calculator running, we need to invoke the asynchronized method getCalculateAsync(), shown in Figure 10, on the controller object.
Figure 10: GetCalculateAsync() method.
This method takes an operation name (e.g. SUM) of type enum, and two doubles. It returns a Task of type string from the API call.
Figure 11 shows how your main class should look like after doing the following steps in order:
- Importing your library components at the top of your class (lines 1-2).
- Instantiating the SimpleCalculatorController (line 15).
- Invoking the GetCalculateAsync() method on it (line 17).
- Waiting for the asynchronized method to finish so we can use the result. This is done by calling wait on the method's return object (line 18).
- Extracting the result and printing it out to the console (lines 19-21)
Figure 11: Main class that uses the APIMATICCalculator library.
You are ready to run the project successfully by clicking on "start" from the main toolbar on the top. This will print out the result to the console, as shown in Figure 11.