Our API uses the HATEOAS principle for resource link (specifically the JSON:API specification).
This creates the need to dynamically replace the base URL when using Stoplight’s mocking feature.
In order to achieve this behavior, I’ve replaced the base url in examples with a variable:
Then added a custom scenario as extra step to the mock server global rules:
The scenario looks like this:
This way when can set the URL in 1 place, making sure the variable is replaced in all mock example responses.
1/ Is this the correct way to do this? Is there an easier solution?
2/ Is there a variable to fetch the hostname from the incoming request, instead of having to hardcode it?
We observe that this does not always work!
1 out of 2 times the extra step is skipped, resulting in the variable not being replaced.
What goes wrong here?
Thanks in advance for your help!