Setup Mockoon application
Download and Install the application from https://mockoon.com/
Launch Mockoon application
Create a new workspace
When you first launch Mockoon, it will ask you to create a new workspace
Enter a name for your workspace and choose a directory where the workspace data will be stored (for example
mockoon-paymentsbbvoucher.json
stored under./examples/mock-bb-payments
directory)Click create
Create a new route
Inside the workspace, click on the
Add a route
button to create a new routeEnter a name for your route
Define the route path (e.g.
/vouchers/voucher_activation
)Select the HTTP method (
GET, POST, PUT, DELETE,
etc.)
Define route responses
Under the route configuration, click on the
Add a response
buttonSet the status code for the response ( e.g.
200 for a successful response
)Configure the headers and the response body for the response
Set rules that must be met to return given response
You can create multiple responses for different scenarios
It’s worth to add that the responses are checked sequentially from first to last, the first rule set that matches is returned. If none match, the default will be returned. Default one can be set by clicking on the drop-down list of all responses and clicking on the flag icon of your choice.
Start Dockerized server
Create
Dockerfile
FROM node:14-alpine RUN npm install -g @mockoon/cli@2.2.1 COPY mockoon-paymentsbbvoucher.json ./mockoon-paymentsbbvoucher.json COPY entrypoint.sh ./entrypoint.sh # Do not run as root. RUN adduser --shell /bin/sh --disabled-password --gecos "" mockoon RUN chown -R mockoon ./mockoon-paymentsbbvoucher.json RUN chown -R mockoon ./entrypoint.sh USER mockoon EXPOSE 3003 ENTRYPOINT ["/entrypoint.sh"]
node:14-alpine
- base imagemockoon-paymentsbbvoucher.json
- workspace created in step 33003
- port on which the server listens (must be the same as in the Mockoon app)Create
docker-compose.yml
version: '3.3' services: test-app: image: payments-bb-voucher-api-image ports: - 3333:3003 networks: - web build: context: . dockerfile: ./Dockerfile volumes: - ./mockoon-paymentsbbvoucher.json:/mockoon-paymentsbbvoucher.json networks: web: driver: bridge
ports: 3333:3003
maps port of the container to the port on your machinetest-app
name of the service fromdocker-compose.yml
Create
test_entrypoint.sh
#!/bin/bash chmod u+x entrypoint.sh docker-compose up -d test-app --build
test-app
name of the service fromdocker-compose.yml
Create
entrypoint.sh
mockoon-paymentsbbvoucher.json
from step 3
From now on server can be started by typing ./test_entrypoint.sh
or simply docker-compose up
invoked from the folder where all the aforementioned files were created.
The server can be called: http://localhost:exposed_port/routes_defined_in_the_mockoon_app