Hi Team, Is it possible to query a database for t...
# help
d
Hi Team, Is it possible to query a database for the response body when using open-source WireMock? For example, in the following mapping, can the "Username" field be populated with data queried from a database?
Copy code
json
{
  "name": "test-account",
  "request": {
    "method": "POST",
    "urlPathPattern": "/my/acc"
  },
  "response": {
    "status": 200,
    "headers": {
      "Content-Type": "application/json"
    },
    "jsonBody": {
      "Msg": {
        "MsgHdr": {
          "MsgNo": "{{jsonPath request.body '$.Msg.MsgHdr.MsgNo'}}",
          "TxnTime": "{{jsonPath request.body '$.Msg.MsgHdr.TxnTime'}}",
          "Username": "Query from the database?",
          "StatusCode": "0",
          "StatusDesc": "Success"
        }
      }
    }
  }
}
l
This isn't available out of the box. You could certainly write a template helper to do this - https://wiremock.org/docs/extensibility/adding-template-helpers/
WireMock Cloud has a feature that might help you. At the moment the Data Sources feature allows you to upload a CSV file of data and they query that data using SQL in your stubs. You can then use the data returned in the response template. https://docs.wiremock.io/data-sources/overview/
A useful comparison of all the differences can be found here - https://www.wiremock.io/comparison
d
thanks Lee!
👍 1