最佳做法和如何支持C#包装不同版本的REST API的对客户端 [英] Best Practices and How to support different versions of REST APIs in C# wrapper on client-side

查看:103
本文介绍了最佳做法和如何支持C#包装不同版本的REST API的对客户端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个C#包装支持我们公司项目的REST的API。然而,这些API正在改变 - 在网址条款(可能会引入URL版本号)和数据对象预计并返回

I have written a C# wrapper to support our company project's REST APIs. However, these APIs are changing now - in terms on URL (may introduce version number in URL) and data objects it expects and returns back.

我想知道什么是对我的C#包装支持不同版本的REST API的最佳做法。

I would like to know what would be the best practice on supporting different versions of REST APIs in my c# wrapper.

和我应该怎么办呢 - 在code设计和类定义术语 - 这样一个包装可以用不同版本的API的无缝连接 - 这应该是可扩展还 - 这样的API的任何更新版本将来也可以轻松支持。

And how should I do it - in terms of code design and class definitions - so that one wrapper can work seamlessly with different versions of API - and it should be extensible also - so that any newer version of APIs in future can also be easily supported.

我已经写C#的包装费是我们的Web服务的API。
我已经使用RestSharp客户端使用在C#包装我们的Web服务的API。

The c# wrapper I have written is consuming our web service APIs. I am already using RestSharp client to consume our web service APIs in c# wrapper.

推荐答案

有一个微妙的怪事你是问。让我重申你说什么:

There's a subtle weirdness to what you are asking. Let me reiterate what you have stated:

1)有在您的组织相同服务的多个版本。或许他们建立像鲍勃建议,/电流/ API ... / V1 / API ... / V2 / API ...等等。也许一些其他的模式。

1) There are multiple versions of the same service at your organization. Perhaps they are established like Bob suggested, /current/api... /v1/api... /v2/api... etc. Or perhaps some other pattern.

2)你想一个C#库要意识到每一个不同的版本的。

2) You want a single C# library to be aware of each of the different versions.

这是第二部分是奇怪。通常,客户端库将只针对特定版本。这将是服务器的责任,以确保服务的新版本要么与旧版本的向后兼容,或者在一个新的URL孤立。

It's this second part that is strange. Normally a client-side library would target a specific version only. It would be the server's responsibility to make sure that new versions of a service were either backwards compatible with old versions, or isolated on a new url.

问问你自己 - 如果你要继续构建这个库,知道相同服务的多个版本,它怎么会看向消费者库的?他们会明确告诉你使用哪个版本?这不是一个问题我会希望有知道的。

Ask yourself this - if you were to go ahead and build this library that was aware of multiple versions of the same service, how would it look to the consumers of your library? Would they have to specifically tell you which version to use? That's not a concern I would expect to have to be aware of.

var client = new MyClient();
client.DoSomething();   // Makes sense    
client.DoSomethingV2(); // Huh?

这篇关于最佳做法和如何支持C#包装不同版本的REST API的对客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆