Mockoon

Also see Wiremocks

“Mockoon is the easiest and quickest way to design and run mock REST APIs. - mockoon.com”

Create Local

  1. Using the Mockoon desktop application create a new local environment and save it locally, I use C:\dev\SWEETAPI\.localdev\mock-server and call the json file something related to the mocks, eg: mock-netsuite.json

  2. An example route could be GET /contact with response

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
{
"Count": 2,
"HasMore": false,
"Items": [
{
"ExternalId": "123e4567-e89b-12d3-a456-426614174000",
"Company": {
"CompanyName": "Acme Corporation"
},
"FirstName": "John",
"LastName": "Doe",
"Email": "john.doe@example.com",
"Phone": "555-123-4567"
},
{
"ExternalId": "987f6543-dcba-9876-fedc-0123456789ab",
"Company": {
"CompanyName": "Globex Industries"
},
"FirstName": "Jane",
"LastName": "Smith",
"Email": "jane.smith@example.com",
"Phone": "555-987-6543"
}
],
"Offset": 0,
"TotalResults": 2
}
  1. You can then use Mockoon desktop to run the collection but its more useful to be part of the local development pipeline running in a container. Docker Compose is a good candidate because you will probably add other service mocks, cache stores, databases ect

You could orchestrate the commands with Make or just use Powershell per the eamples below.

Define the docker-compose.yml file, create a service using the image mockoon/cli and point the volume to the location of the Mockoon local environment

1
2
3
4
5
6
7
8
9
services:
mockoon:
image: mockoon/cli:9
container_name: mockoon
working_dir: /mock-server
volumes:
- ./.localdev/mock-server:/mock-server
ports:
- 3001:3001
  1. Run the mocks using Powershell, create run-local.ps1 in the root and execute the docker compose command
1
docker compose up --wait mockoon

Here I explicily called the service mockoon and if this was your only mock, you could just run the container, this came from the docs:

1
docker run -d --mount type=bind,source=/home/your-data-file.json,target=/data,readonly -p 3000:3000 mockoon/cli:latest --data data --port 3000

References