Default Mock response when exact match fails

Archived topic — some details may be out of date.
Mock servers built from saved collection examples are still supported. Postman now also has code-based mocks: JavaScript request handlers plus a config.yaml, stored as files in your Git repository, which you can run locally or deploy. Create one in the app, or use the Postman CLI to generate one from an OpenAPI spec, collection or dataset (postman mock generate) and run it (postman mock run). See About mocks and Create a mock.
Working with an AI coding agent? The Postman plugin can build and run mocks for you.
For current help, see the Postman docs, try the free Postman tools (no account needed), or join us on Discord.

Hello team,

I’ve used the search in postman + googled + stackoverflowed this before I decided to ask.

Is there a way to default to a particular example response when exact url match fails

scenario
bwm_118
bmw_330
bmw

When calling → https://myserver.com/items/bmw_080, I need to see the example response created for bmw

This works well with wildcard variable, however it’s a catchall for all examples in the collection.

What I need instead is a specific catchall for all bmw example responses, then when I have requests for
audi_rs
audi_80
audi

audi would serve as a catch all for audi not the bmw one.

I really hope this makes sense, thanks for the help!

Hi @supply-technologist8

I’m not sure I fully understand what you are trying to achieve, but here is a link for info on the matching algorithm…

If this doesn’t help could you provide a little more clarity?
I’m not sure what is meant by ‘catch all’ as my understanding is, that you would only return 1 example at a time depending on the response.

Hi @w4dd325 James,

Thanks for your reply, I will try to get explain better.

Say I have several example requests with example responses

POST url/path/audi_123
POST url/path/audi_456
POST url/path/audi

Every request sent to name_* which is not a match to _123 and _456 I need to resolve to the default audi one

For example POST url/path/audi_0007 as not found should use the response in url/path/audi one instead.

Something like a wildcard variable to match not existing examples as described in the link you provided, but to somehow match the substring i.e. audi

So for my other examples in the collection I have which are

path/bmw_118
path/bmw_330
path/bmw

If I send a request to path/bmw_420 I then get not the bmw response but the audi one, because the matching alg is ordering them and gives me the top one.

So Id like to have a default reaponse for a particular group if that makes sense.

Thank you