Mocking External APIs

Our applications will often have to integrate with APIs provided by external parties. These external APIs may not be available for testing in our local and DEV environments.

In order to test the integrations on local or DEV, we would have to mock the APIs.

Writing our own dummy application to simulate the external APIs is time consuming and error prone. Instead, we can make use of tools such as Mockoon to simulate the APIs easily.

Requirements for running locally

To run Mockoon locally independent of Docker:

  • install Mockoon GUI OR
  • use choco install mockoon if you’re using Chocolatey for Windows

Requirements for deploying Mockoon to a server

To set up Mockoon such that it can be deployed to a server, you need the following:

  • Docker
  • Mockoon
    • Not strictly necessary, but makes it easier to modify the Mockoon mock endpoints
  • Mockoon CLI
    • Required to Dockerise any Mockoon environment

Learning Mockoon

Refer to Mockoon documentation

If you’re provided with the OpenAPI specs for the APIs to be mocked, Mockoon can easily import the APIs.

Use Faker.js with Mockoon to generate fake data for testing.

Treat your Mockoon environment like any other web API service. Use applications such as Postman and Insomnia for testing.

Dockerising Mockoon

Refer to Mockoon CLI documentation for how to build a self-contained Docker image that will run your Mockoon environment.

Deploying your Mockoon image

As the steps for deploying Docker images to DEV environment will vary across projects, this document will not cover the deployment process. Your Mockoon image can be deployed like any other Docker image.