adhi narayan
adhi narayan

Reputation: 320

get a particular object from jsonBody with query param of request url in wiremock

What should be the mapping object if 1) I need to pass my query 2) the query should be used to send one object out of an array of objects

 curl -X POST --data '
{ "request": 
           { "url": "/jsons?id=someID", "method": "GET" },
 "response": 
           { "status": 200, "jsonBody": {"objs":[{"id":"1","name":"abc"},{"id":"2","name":"cde" 
                                                 {"id":"someID","name":"efg"}]}}}
'http://localhost:8080/__admin/mappings/new

I want the above url to return just {"id":"someID","name":"efg"}

How should i change the above mapping to get the desired output

Upvotes: 1

Views: 196

Answers (1)

Anish Aralikatti
Anish Aralikatti

Reputation: 365

The response should have one object for that particular get request with query param and not array of objects.

For your example it should be something like this

curl -X POST --data '
{ "request": 
{ "url": "/jsons?id=someID", "method": "GET" },
"response": 
{ "status": 200, "jsonBody": {"objs": {"id":"someID","name":"efg"}}}}
'http://localhost:8080/__admin/mappings/new

Upvotes: 1

Related Questions