Implement integrations
REST services
REST services are used to integrate an external API with the current project.
Note: The external API could be integrated by adding the specification as an API dependency or not.
Below is an example of the implementation of a REST service which is called GetExternalCustomer
and belongs to the
integration namespace cus
.
// Make an HTTP request to an operation. The path and query parameters must have the same types
// and name as they are defined in the API dependency specification.
const response = await this.apis.namespacePrefix.tagName.OperationId({pathParmamidentifier: “value1”});
// Check whether the call was successful and, if it is, give the name of the customer as output
if (response.status === 200) {
// Initialize the output entity
this.output = this.factory.entity.cus.RestServiceIdentifier_Output();
// Initialize the output property
this.output.property1 = response.body.property1;
Attention: Properties of type String with format Date must be initialized like
this:
strProperty = "2019-09-01"
. Additionally, properties of type String with format Date-Time must be
initialized like this: strProperty = new Date("2019-09-01").toISOString()
. Where the date structure is strictly "
<year>-<month>-<day>".Make external requests using request utility
When creating external calls to APIs you can retrieve the API binding option and if it contains a ca_cert property, you can use it to construct an SSLConfig object that can be used when making external API calls.
public async execute(): Promise<void> {
// get binding of petstore API
const apiBinding = await this.apiBindings.getPetstore();
// make the request using the custom ca_cert defined in the api binding
await this.util.request.get('www.google.com', {param1: 'val'}, {header1: 'val'}, { ca_cert: bind.ca_cert});
}
Warning: Whenever you are querying external services, you should make sure, that all communication to
such services are encrypted and all TLS-encrypted protocols including HTTPS use version 1.2+. The connection to the
target service should be authenticated (certificate validation should be enabled)!
Make API facade operations calls
If your API dependency's API binding already contains ca_cert
value, then this ca_cert
value will be implicitly
used to make external API facade operation calls.