This message was deleted.
# general
s
This message was deleted.
a
What’s different about the request where you want only the object where id=2 vs. the request where you want the entire contacts array?
j
I wanted that when filtering the request by a specific id, it would only return the json with part of that id and not its entire json. I tried to do it through parameters but it didn't work.
r
Create a new stub using path regex matching
/contacts/[0-9]+
(see "Regex matching on the path only"). Enable response templating. Set the response body to be something like:
Copy code
{
  "id": "{{request.path.[1]}}",
  "firstName": "Suki",
  "lastName": "Patel",
  "email": "<mailto:spatel@example.com|spatel@example.com>",
  "dateAdded": "2020-11-12",
  "companyId": "123"
}
j
Thank you, I understood better. But in this case the response is dynamic depending on the inputs that I put. Or the way you indicated, @Rob Elliot, works for cases where I don't want the response to be dynamic depending on the inputs, but when inserting id=2 in the url, for example, it will fetch only the json with id=2, ignoring id=1 and id=3?
r
Stubs are independent of each other; if you specifically need
GET /contacts/1
to return the first element in the
GET /contacts
response, and so on, you will need to add a specific stub for each contact with the appropriate path and body. Generally it's a better idea not to, and to use random data or data from the request, but it will depend on your usecase.
j
Thank you so much for your help.