Create an Integration Builder Connector to an API Builder Microservice
In this post, we'll describe how to create an Integration Builder connector to an API Builder Microservice.
Join the DZone community and get the full member experience.Join For Free
In this post, we'll describe how to create an Integration Builder connector to an API Builder Microservice. We'll create an API Builder project, run it, and export its swagger definition. Then, we'll import the swagger into Integration Builder and create a connector that can be used in Integration Builder flows.
Create Your API Builder Project
In this section, we'll create an API Builder project and get the swagger for it.
- Follow the instructions and create an API Builder project, run it, and make sure you can log into the console and run the default, built-in greet API.
- Switch from basic authentication to api key authentication by editing the /config/default.js file and make note of the API key (in the same file) as we'll need it later
- Look for the property called accessControl
- Change apiPrefixSecurity from basic to apikey
Stop and restart your API Builder project and make sure the greet API still works
Get the swagger file, either from the console (by clicking on the Download Swagger button) or from http://localhost:8080/apidoc/swagger.json
Since Integration Builder is a SaaS product and API Builder is running on localhost, we need a way to enable access of API Builder to Integration Builder. We'll use ngrok to expose a public URL to API Builder. This was previously described here. Since API Builder is listening on port 8080 by default, use:
ngrok http 8080
This will create a public URL that maps to http://localhost:8080. Make note of the ngrok public URL, as we'll need it shortly.
You may also like: Create an API Builder Multi-Container Application Using Docker: Part 2
In this section, we will create an Integration Builder connector to our API Builder microservice by importing the API Builder swagger file.
We can edit the swagger and replace:
with the ngrok public URL, e.g.:
Alternately, we can change this url in Integration Builder after importing it. Let's do the latter.
- Go to Integration Builder at https://platform.axway.com
- Click on the Connectors tab and click on the BUILD NEW CONNECTOR button
- Click on the Import button
- Click on the Swagger tile and click the FROM COMPUTER button to select your API Builder swagger file
- Click on the CONTINUE IMPORT button and select what APIs you want to import (e.g. I selected greet only).
- Click the IMPORT button
- Update the Base URL with your ngrok public URL (instead of localhost:8080.
- Leave Authentication as Custom
- Name: API Key
- Key: APIKey (this is the API Key name in API Builder)
- Type: test 128
- Required: true
- Name: APIKey
- Type: configuration
- Vendor Name: APIKey
- Type: Header
At this point, we’re done and we can create an instance of this connector and test it as follows:
- Click on the Connectors tab and find the connector we just created. It should have the same name as your API Builder project name (e.g. apibdemo) and has an Axway logo. Hover over the connector tile and click on Authenticate.
- Authenticate your connector by giving it a name and entering the API Key from your API Builder /conf/default.js file
- Click the CREATE INSTANCE button
- Click the Test in API Docs tile. Click the GET /greet API and click the Try it out button
- Enter any string in the username field and click on the Execute button
Stop your API Builder project from running (ctrl-C).
Following the instructions here, let's create and run our API Builder microservice in a Docker Container and see what, if any, changes need to be made to the Integration Builder connector we just created. Hint: None!
Let's create our Docker container as follows:
docker build -t apibdemo ./
Note that my API Builder project is called apibdemo. In the command above, I am specifying apibdemo as the name of the resulting Docker image
Run your container using:
docker run --name apibdemo -p 8080:8080 -d apibdemo
Note that we are mapping API Builder port 8080 to the host port 8080
Go back to Integration Builder and test your greet API, and see that it's working just as before. The difference is that now your API Builder microservice is running in a Docker container.
When you deploy your API Builder container into a production environment, you can modify the Integration Builder connector's base address with the URL corresponding to your production environment.
In this post, we demonstrated how to import an API Builder swagger into Integration Builder in order to create a connector for our API Builder microservice. This enables us to leverage API Builder microservices in your Integration Builder flows.
Published at DZone with permission of Leor Brenman, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.