There are several ways to do this.
One way, for example, is to simply use attribute routing to give it a different path. Create a separate method, for example, specify the path /vtest/customer/2 and, if users access this version /vtest/ (or v2 or 3 or something else), return the test data / new version. See an example in this question.
Another way is to place your "test data" API in another application on your server and indicate that your web.config file checks the versions of your database / source data. Using IIS, you must configure two different applications (one for testing, the other for live), and the base URL will be different, for example: https://myapi.mysite.com/appname1/v1/customer/2 vs https://myapi.mysite.com/appname2/v1/customer/2 , and your application name may be something like live vs test . Check out this simple example.
You can also just place them on different servers in general, which will lead to a {fqdn} change between test and live versions (for example, server.com/v1/customer/2 vs testserver.com/v1/customer/2 ) - this is what I am doing on my current assignment, and I find it very efficient as it isolates the Live / Test data (and API versions), avoiding confusion between them.
I also found this blog post detailing how to do this with a namespace
In other words, there is not only one best / right way to do what you want, it all comes down to how you (or your company / boss / team) want to structure and control the test against live data in your APIs. Take a look at these options To see which one is better in your case, I hope I could help.
Yuriw
source share