English 中文(简体)
REST Api服务器的移动设备版本编码
原标题:encoding mobile-device versioning for REST Api server

我们有基于HTTP的restful api。在其他客户端中,我们还有移动设备客户端(例如iphone)。问题是,有几个不同版本的iphone应用程序(1.0、2.0)。因为它们是分布式的,我们无法控制哪个应用程序版本在调用我们。

要在服务器端识别应用程序版本,我看到以下选项:

  1. device must append URL parameter (e.g. /foo?iphone-app-version=1.0) : A bit yucky, but good thing is that I can see it always on server-logs (URL is always logged)
  2. we authenticate api-clients with HTTP digest. We could encode the app-version inside the username (e.g. iphone_1_0): Good thing it is logged in server logs, but only works for resources which are exposed as HTTP digest.
  3. device must use custom HTTP-header, e.g. X-IPHONE-APP-VERSION: In my view the cleanest approach, but we don t log HTTP headers in server logs (for log-noise it is switched off). So later analyzation is not possible.

你有首选的方法或其他选择吗?

编辑:对于上面的版本控制,我不是指api版本控制/内容协商。它是移动设备的版本。

最佳回答

我决定定制X-xxx-USER-AGENT。决定不采用更标准的“用户代理”的主要原因是它已经被http客户端库或移动设备信息“污染”了。自定义X-xxx-USER-AGENT更容易为服务器解析,并且不干预http库,http库通常会设置它,并可能覆盖自定义条目。

问题回答

您可以使用Accept Header来允许客户端通过标识其支持的媒体类型的版本来声明其具有哪些功能。例如。

移动应用程序可以:

GET /server/foo
Accept:  application/vnd.acme.fooappV1+xml

当你引入不向后兼容的新功能时,你可以告诉新的更新客户端发送,

GET /server/foo
Accept:  application/vnd.acme.fooappV2+xml

Then your server knows the capabilities of the client it is talking to. You could also get the new clients to do this:

GET /server/foo
Accept:  application/vnd.acme.fooappV1+xml, application/vnd.acme.fooappV2+xml

这样,您就可以缓慢地将服务器资源迁移到新的格式。如果端点交付application/vnd.acme.fooappV1+xml,那么客户端将恢复到原来的方式。如果端点返回application/vnd.acme.fooappV2+xml,则新代码可以接管。

使用这种方法,不需要更改URI,因此书签和统计信息仍然有效。迁移到新格式可以随着时间的推移逐步完成,并且可以逐步取消对旧客户端的支持。





相关问题
How to set response filename without forcing "save as" dialog

I am returning a stream in some response setting the appropriate content-type header. The behavior I m looking for is this: If the browser is able to render content of the given content type then it ...

Which Http redirects status code to use?

friendfeed.com uses 302. bit.ly uses 301. I had decided to use 303. Do they behave differently in terms of support by browsers ?

Does HttpWebRequest send 200 OK automatically?

Background: I am implementing Paypal IPN handler. This great article on Paypal states that I am required to send a 200 OK back to Paypal after I read the response. The processing of IPN request is ...

Java HTTPAUTH

我试图把桌面应用程序连接起来,我是同D.icio.us api @ Delicious Alan书写的,简单地向他们提供我的用户名和密码,并请他把书记上写给我......。

Finding out where curl was redirected

I m using curl to make php send an http request to some website somewhere and have set CURLOPT_FOLLOWLOCATION to 1 so that it follows redirects. How then, can I find out where it was eventually ...

热门标签