importWebApiClient
Imports a Web API client library.
This is suitable for all modules of business service components.
Syntax
Copy
function importWebApiClient(libraryName : string, baseUrl : string, timeoutSeconds? : number): any;
| Parameter | Type | Description |
|---|---|---|
library
|
string | Name of the Web API client library. |
baseUrl
|
string | Base URL of the web service accessed through the API. |
timeoutSeconds (optional) |
number | Time in seconds to wait before the HTTP request times out. Default: 100s. |
Return Value
Returns a JSON object containing the API specifications. The object exposes methods matching the API's endpoints and has full IntelliSense auto-complete support.
Examples
In this example:
- We import the FintechOS Web API client library which stores the specifications for the http://localhost:52149 API into an object called client.
- We store the authentication token for the jdoe user who has a password in the authToken variable. For details on the FintechOS API token-based authentication, see the API Reference Guide.
- We return all the records stored in the employees entity in the data variable. For details on how to run queries through the FintechOS API, see the API Reference Guide.
- We store the returned data in the trace_roll.log file. For details, see ftos.logging.log.
Copy
let client = importWebApiClient('FintechOS', 'http://localhost:52149');
try {
var authToken = client.authorize.getToken({
client_id: 'client_id',
username: 'jdoe',
password: 'pass'
});
if (authToken && authToken.access_token) {
let data = client.openApi.query({
apiInfo: {
token : authToken.access_token
},
request: {
entity: {
name: "employees",
alias: "emp"
},
distinct: false
}
});
log(data);
}
else
throw new Error('Invalid authentication!');
}
catch(err) {
log(err);
throw err;
}