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
Note: The code for this tutorial is provided as a zip file available for download here.
1. Setting up the environment:
Following this tutorial here, a library is already generated, downloaded, and ready for use.
You can use your favorite text editor.
2. SDK generation instructions:
After choosing Angular JS 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.
3. SDK installation instructions:
In order to use your library, you have to unzip it first.
Extract the unzipped file to a new folder, as shown in Figure 2.
4. Creating a sample application:
The following section explains how to create a new application that uses your generated apimatic calculator library.
4.1 Starting a new project
On starting a new project, create a new folder with your project name "myCalculator".
Inside this folder, there should be:
- A new file with the file extension (.html). This file will have HTML and JavaScript code that will use your library.
- A new folder called "scripts" that will contain all the scripts needed for running your application.
Create a "main.html" file and a "scripts" folder inside myCalculator folder.
Figure 3 shows the correct folder contents.
4.2 Creating a simple Angular JS application:
Since Angular JS is used for client-side web development, in order to use our library, we have to develop an application first. For tutorial purposes, we will develop a simple single-page application to demonstrate using our generated SDK.
To develop a single page application, we will use an open source example provided here, as a reference.
Figure 4 shows how your "main.html" file should look like at this stage, after doing the following steps:
- Adding the script that provides the singe-page app (line 2)
- Adding a controller to a <div> (line 6)
4.3 Using your library in your project:
In order to use your library, first you have to add its scripts to your html file using the "<script>" tag.
After that, you need to instantiate its objects and invoke their functions.
To get our calculator running, we need to invoke the asynchronous function getCalculate, shown in Figure 5, on the controller object.
This function takes an "input" object that contains:
- An operation of type enum (e.g. SUM)
- Two doubles; x and y
Figure 6 shows how your main class should look like after doing the following steps in order:
- Adding your SDK scripts at the top (lines 4-13)
- Instantiating the SimpleCalculatorController (line 32)
- Invoking the getCalculate() function on it (line 32)
- Defining the input parameter for the function (lines 26-30)
- Displaying the result to the webpage (line 19)
How it works:
- The "PageCtrl" controller instantiates the "SimpleCalculatorController" controller and calls its calculate method. On success, it will assign the "message" to a string (line 34) that contains the result of the operation (sum of two numbers in this case). The "message" is then displayed in the webpage (line 19)
- On failure, it will print an error message to the console (line 37)
Note : This is a basic application to show how to use your SDK in your Angular JS code. The means used to display the result and/or error messages, the format of the html page and the complexity of your application is up to you to control, improve and implement.
You are ready to run the application .
4.3 Running your application:
To run this application, double-click on your "main.html" file to open it in your browser.
Figure 7 shows how the webpage would look like at this stage.
Comments
0 comments
Please sign in to leave a comment.