REST GET API的推荐日期格式 [英] Recommended date format for REST GET API

查看:186
本文介绍了REST GET API的推荐日期格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

REST GET API的建议时间戳格式是这样的:

  http://api.example.com/ start_date / {timestamp} 

我认为实际的日期格式应该是ISO 8601格式,如 YYYY-MM-DDThh:mm:ssZ UTC时间。



我们是否应该使用ISO 8601版本,无连字符和冒号,例如:

  http://api.example.com/start_date/YYYYMMDDThhmmssZ 
解决方案

REST没有推荐的日期格式。真的可以归结为最适合您的最终用户和您的系统。就个人而言,我想坚持像ISO 8601(url编码)这样的标准。



如果没有丑陋的URI是一个问题(例如,不包括的url编码版本: - 在你的URI)和(人类)可寻址性不是那么重要,你也可以考虑时代时间(例如 http://example.com/start/1331162374 )。该URL看起来有点干净,但是您确实无法读取。



/ 2012/03/07 是另一个格式你看到很多。你可以扩大我想的。如果你去这条路线,只要确保你总是在GMT时间(并在你的文档中清楚),或者你也可能想要包括某种时区指标。



最终归结为适用于您的API和最终用户的功能。您的API应该适合您,而不是为您服务; - )。


What's the recommended timestamp format for a REST GET API like this:

http://api.example.com/start_date/{timestamp}

I think the actual date format should be ISO 8601 format, such as YYYY-MM-DDThh:mm:ssZ for UTC time.

Should we use the ISO 8601 version without hyphens and colons, such as:

http://api.example.com/start_date/YYYYMMDDThhmmssZ

or should we encode the ISO 8601 format, using for example base64 encoding?

解决方案

REST doesn't have a recommended date format. Really it boils down to what works best for your end user and your system. Personally, I would want to stick to a standard like you have for ISO 8601 (url encoded).

If not having ugly URI is a concern (e.g. not including the url encoded version of :, -, in you URI) and (human) addressability is not as important, you could also consider epoch time (e.g. http://example.com/start/1331162374). The URL looks a little cleaner, but you certainly lose readability.

The /2012/03/07 is another format you see a lot. You could expand upon that I suppose. If you go this route, just make sure you're either always in GMT time (and make that clear in your documentation) or you might also want to include some sort of timezone indicator.

Ultimately it boils down to what works for your API and your end user. Your API should work for you, not you for it ;-).

这篇关于REST GET API的推荐日期格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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