Is there a standard date / time representation format in a URI?

I am creating an API endpoint that takes a DateTime parameter as a parameter.
It is recommended not to use the : character as part of the URI, so I cannot just use the ISO 8601 format.

So far I have been considering two formats:

A) Exclamation mark as a minute separator:

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

It looks unnatural and even with clear documentation, API users should be wrong.

B) URI segment for the DateTime part:

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

It looks unreadable. In addition, as soon as I add additional numerical parameters, this will become incomprehensible!

Is there a standard / convention for representing date / time in a URI?

+4
source share
2 answers

I would use a standard data exchange format.

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

+6
source

You can use : in URI paths.

The double is a reserved character, but it does not have a dividing role in the path segment. Therefore, the following should apply:

If a reserved character is found in the URI component, and the demarcation role is not defined for this character, then it should be interpreted as representing a data octet corresponding to this character encoding in US-ASCII.

There is only one exception for relative path references :

A path segment that contains a colon character (for example, "this: that") cannot be used as the first segment of a relative path link because it is mistaken for a schema name. For this segment, a period segment must precede (for example, "./this:that") to create a relative path reference.

But note that some encoding libraries may skip colon encoding in any case.

+1
source

Source: https://habr.com/ru/post/1499598/


All Articles