API First: From Zero to Hero (Part 2)

Importing an API into API Gateway

Moving on with the integration tests, we will import our API into the API Gateway locally, to validate the import process and enable the use of our test through the gateway. We will have something similar to the diagram below:

Provisioning the API gateway

To facilitate the provisioning of resources, we will start to use a Makefile to centralize the scripts and enable the reuse of them.

make -k run-integration-tests
  • We created a shared network that will be used by Kong and its database (Postgres), the backend of our API (prism) and the client of our API (newman)
  • Provisioned the postgres database used by Kong
  • We provisioned Kong using database
  • We cleaned-up by removing the created containers and the network, this is because we want them to live only during the test execution

Provisioning the API backend (prism)

Now we will use the same command (with some minor changes) that we used to create the Prism Mock and add it to our Makefile, to automatically provision the mock API backend.

docker rm --force prism
make -k run-integration-tests

Importing the API

We will now import our API definition inside the Kong API Gateway.

Adding the registry as insecure (Optional — self-generated certificates)

Before using the tool, we will have to configure docker’s registry as an insecure in the docker daemon, to avoid problems due to self-generated certificates.

{
"insecure-registries" : [ "registry.domain.com" ]
}
systemctl restart docker

Pulling the swagger-to-kong image:latest

To ensure that we have the last image available for the swagger-to-kong component, pull the image as shown below:

docker pull registry.domain.com/ci-tools/swagger-to-kong:latest
  • Import the openapi petstore-v3.0.yaml definition
  • Changes the address of the item servers in openapi with the value of the environment variable OPENAPI_SERVER, which in turn points to the backend (Mock). This setting is applied in Service Kong.
  • Invokes the kong Admin API to create the appropriate Service and Route.

Executing the collection via Makefile

With everything working properly, we can now invoke our collection with Newman using our Makefile.

make -k run-integration-tests

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
3Bit Technologies

3Bit Technologies

Cloud Specialists providing professional services with DevOps, BigData, Cloud Native Applications and Security. https://www.3bit.com.br/3bit