Skip to content

Latest commit

 

History

History
103 lines (89 loc) · 2.36 KB

env.md

File metadata and controls

103 lines (89 loc) · 2.36 KB

Environment

The data stored in the environment can be used simultaneously in the Response and in the webhook

Faker

You can use Faker to generate random data

[
    {
        "env": {
            "id": "{{faker.uuid}}",
            "iban": "{{faker.iban('LV')}}",
            "dateTime": "{{faker.dateTimeBetween('-1 week', '+1 week').format('Y-m-d H:i:s')}}",
            "amount": 1000
        },
        "response": {
            "content": {
                "json": {
                    "id": "{env.id}",
                    "iban": "{env.iban}",
                    "createdAt": "{env.dateTime}",
                    "updatedAt": "{env.dateTime}",
                    "amountInText": "{env.amount} USD",
                    "amountSourceDataType": "{{env.amount}}"
                }
            }
        },
        "webhooks": [
            {
                "url": "https://api.site.com/webhook",
                "json": {
                    "id": "{env.id}",
                    "iban": "{env.iban}",
                    "amount": "{{env.amount}}",
                    "createdAt": "{env.dateTime}",
                    "updatedAt": "{env.dateTime}"
                }
            }
        ]
    }
]

Response:

{
    "id": "ea6143fe-bf40-3f1a-90d3-e6872204888d",
    "iban": "LV89ORDR6OQ6J4G22N0T3",
    "createdAt": "2023-02-17 04:24:55",
    "updatedAt": "2023-02-17 04:24:55",
    "amountInText": "1000 USD",
    "amountSourceDataType": 1000
}

Webhook will send the data:

{
    "id": "ea6143fe-bf40-3f1a-90d3-e6872204888d",
    "iban": "LV89ORDR6OQ6J4G22N0T3",
    "amount": 1000,
    "createdAt": "2023-02-17 04:24:55",
    "updatedAt": "2023-02-17 04:24:55"
}

Server environment

You can pass the environment parameters when starting the container

docker run --rm -it -v $(pwd)/mocks:/app/mocks -p 8080:8080 -e DOMAIN=api.server.com lav45/mock-server:latest
[
    {
        "response": {
            "content": {
                "json": {
                    "domain": "{{env.DOMAIN}}",
                    "url": "https://{env.DOMAIN}/v1",
                    "undefined": "{{env.SSS}}"
                }
            }
        }
    }
]

Response:

{
    "domain": "api.server.com",
    "url": "https://api.server.com/v1",
    "undefined": null
}