https://linen.dev logo
#general
Title
# general
s

Sashidhar J

03/31/2023, 2:19 PM
Hi All, Not sure if this is a possibility. Can we do a if condition in wiremock mapping to pick the response body based on a certain input value(s)
a

Aaron

03/31/2023, 2:31 PM
Like a request query parameter or request body value?
s

Sashidhar J

03/31/2023, 3:35 PM
Its based on the request body value
a

Aaron

03/31/2023, 4:38 PM
Yep! So you can take the values from the request body and use that to determine what your response body or bodyFile is
One sec, I’ll get an example
So, the following mapping:
Copy code
{
  "request": {
    "url": "/test"
  },
  "response": {
    "status": 200,
    "bodyFileName": "{{ jsonPath request.body '$.filename'}}.json"
  }
}
Will return the value of the
filename
key in the request body. So, a request with a body like
{ filename: "test" }
, would resolve to
test.json
, and serve up the file at
__files/test.json
.
2 Views