Arnold Zokas
Arnold Zokas

Reputation: 8580

Is there standard format for representing date/time in URIs?

I am building an API endpoint that accepts DateTime as a parameter.
It is recommended not to use : character as part of the URI, so I can't simply use ISO 8601 format.

So far I have considered two formats:

A) Exclamation mark as minute delimiter:

http://api.example.com/resource/2013-08-29T12!15

Looks unnatural and even with clear documentation, API consumers are bound to make mistakes.

B) URI segment per DateTime part:

http://api.example.com/resource/2013/08/29/12/15

Looks unreadable. Also, once I add further numeric parameters - it will become incomprehensible!

Is there standard/convention for for representing date/time in URIs?

Upvotes: 6

Views: 1848

Answers (2)

unor
unor

Reputation: 96697

You can use : in URI paths.

The colon is a reserved character, but it has no delimiting role in the path segment. So the following should apply:

If a reserved character is found in a URI component and no delimiting role is known for that character, then it must be interpreted as representing the data octet corresponding to that character's encoding in US-ASCII.

There is only one exception for relative-path references:

A path segment that contains a colon character (e.g., "this:that") cannot be used as the first segment of a relative-path reference, as it would be mistaken for a scheme name. Such a segment must be preceded by a dot-segment (e.g., "./this:that") to make a relative-path reference.

But note that some encoding libraries might percent-encode the colon anyway.

Upvotes: 1

Alberto
Alberto

Reputation: 1863

I'd use the data interchange standard format.

Check this: http://en.wikipedia.org/wiki/ISO_8601

Upvotes: 6

Related Questions