Web API URL Test Version

For our Web api project, we use the following URL version control system:

HTTPS: // {FQDN} / {apiVersion} / {apiResourceName} / {resourcePath} {Parameters}

?

for example, we can have something like the following:

https://myapi.mysite.com/v1/customer/2

Now let's look at the above, let's say you want to release two versions for the client (live, test). One live version (work with real-time data), and the other is a test (work with test data for a client development test).

For live, I could easily use the one I mentioned: https://myapi.mysite.com/v1/customer/2 .

What do you call the test version of the above api? What is the test version of v1 api url version? Can I specify a test api url?

Also, what are the best methods for the {fqdn} API fully qualified domain name when using URL versioning?

+7
rest api asp.net-web-api restful-architecture restful-url
source share
5 answers

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.

+2
source share

I think the title of your question is misleading. The problem you are trying to solve is not a version (because your client is connecting to the same version of your application: v1). This is about several environments: one for live data and one (or more) for test data.

At my company, we solve this problem using the hostname. At https://live.mysite.com/api/v1 we host the v1 API associated with real-time data. At https://nodex.mysite.com/api/v1 we host the v1 API associated with the test data. Our clients can request new nodes as necessary (for example, client1-devnode.mysite.com/api/v1 for development against and client1-testnode.mysite.com/api/v1 for testing. Each node receives its own set of test data.

+1
source share

Most live projects of different servers for different environments. Instead of using different versions of the API endpoints, you should use different servers for different environments, such as:

For Prod / live: https://myapi.mysite.com/v1/customer/2

For the test: https://myapi.mysitetest.com/v1/customer/2

For Dev: https://myapi.mysitedev.com/v1/customer/2

You need to set the environment properties for the different backend endpoints that you click. For example: test.properties/dev.properties/live.properties

0
source share

With my API development experience, I found that there are 2 ways to make a server (test / developer) / live. I will give an example with your HTTPS link type : // {FQDN} / {apiVersion} / {apiResourceName} / {resourcePath} {Parameters}

?

In your case, you can use either settings based on and type of testing

What are settings based on?

The settings are based on the fact that your server, for example https://rest.mysite.com/v1/customer/2 will act as a test if you or your client set the server status of the server test in it , and if in live mode, the status to live . This method is good in some cases, but for testing and for living at the same time, this type is not recommended.

What is a link | URL | URI based?

This method has two types of authentication request: test or live

  • One way is to set the test as a parameter https://api.mysite.com/ test / v1 / customer / 2 and without verification it goes live
  • The second way is to install api for testApi or apiTest, for example https: // testapi .mysite.com / v1 / customer / 2 or https: // apitest .mysite.com / v1 / customer / 2. Thus, the client has both a test and a living one, and he can conduct testing and have a live project.

And do not forget about security, always check the client and check before providing access in real time.

0
source share

As an option, you can use a custom header. If the request contains a custom header -> redirect request to check the version of the API.

0
source share

All Articles