Boost API example documentation.
, Simple calculator API hosted on APIMATICInstall the SDK by adding the following dependency in your project's pom.xml file:
<dependency>
<groupId>io.sdks</groupId>
<artifactId>apimatic-calculator-sdk</artifactId>
<version>1.0.0</version>
</dependency>
You can also view the package at: https://mvnrepository.com/artifact/io.sdks/apimatic-calculator-sdk/1.0.0
The generated code and the server can be tested using automatically generated test cases. JUnit is used as the testing framework and test runner.
In Eclipse, for running the tests do the following:
- Select the project MergedApiLib from the package explorer.
- Select
Run -> Run as -> JUnit Test
or useAlt + Shift + X
followed byT
to run the Tests.
Note: Documentation for the client can be found here.
The following parameters are configurable for the API Client:
Parameter | Type | Description |
---|---|---|
environment |
Environment | The API environment. Default: Environment.PRODUCTION22 |
httpClientConfig |
ReadonlyHttpClientConfiguration |
Http Client Configuration instance. |
oAuthClientId |
String |
OAuth 2 Client ID |
oAuthClientSecret |
String |
OAuth 2 Client Secret |
oAuthToken |
OAuthToken |
Object for storing information about the OAuth token |
The API client can be initialized as follows:
MergedApiClient client = new MergedApiClient.Builder()
.httpClientConfig(configBuilder -> configBuilder
.timeout(0))
.clientCredentialsAuthCredentials("OAuthClientId", "OAuthClientSecret")
.environment(Environment.PRODUCTION22)
.build();
The SDK can be configured to use a different environment for making API calls. Available environments are:
Name | Description |
---|---|
production22 | Default Production environment, This environment connect to the LIVE calculator API |
development | development |
This API uses OAuth 2 Client Credentials Grant
.
Your application must obtain user authorization before it can execute an endpoint call in case this SDK chooses to use OAuth 2.0 Client Credentials Grant. This authorization includes the following steps
The fetchToken()
method will exchange the OAuth client credentials for an access token. The access token is an object containing information for authorizing client requests and refreshing the token itself.
try {
OAuthToken token = client.getClientCredentialsAuth().fetchToken();
// re-instantiate the client with oauth token
client = client.newBuilder().oAuthToken(token).build();
} catch (Throwable e) {
// TODO Handle exception
}
The client can now make authorized endpoint calls.
It is recommended that you store the access token for reuse.
// store token
storeAccessToken(client.getClientCredentialsAuth().getOAuthToken());
To authorize a client from a stored access token, just set the access token in Configuration along with the other configuration parameters before creating the client:
// load token later...
OAuthToken token = loadAccessToken();
// re-instantiate the client with oauth token
client = client.newBuilder().oAuthToken(token).build();
package com.example;
public class Main {
public Main() {
MergedApiClient client = new MergedApiClient.Builder()
.httpClientConfig(configBuilder -> configBuilder
.timeout(0))
.clientCredentialsAuthCredentials("OAuthClientId", "OAuthClientSecret")
.environment(Environment.PRODUCTION22)
.build();
try {
OAuthToken token = client.getClientCredentialsAuth().fetchToken();
// re-instantiate the client with oauth token
client = client.newBuilder().oAuthToken(token).build();
} catch (Throwable e) {
// TODO Handle exception
}
// the client is now authorized; you can use client to make endpoint calls
}
}