Search code examples
wiremockwiremock-standalone

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


Solution

  • 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