In a REST URL what does the meaning for <pathPram>:<xyz> stands for? And how to process it in sprinboot?

43 views Asked by At

For Ex: http://market.com/fruit:banana/price Here by term one can understand that fruit is a category and banana is one of the values. But I need more understanding on it in order to process it. Also what if the values are comma sepeareted? Ex: http://market.com/fruit:banana,mango/price Can anybody help on this?

1

There are 1 answers

0
VoiceOfUnreason On

In a REST URL what does the meaning for : stands for?

Short version: whatever that specific URI designer wants it to stand for.


Longer version: the production rules for path segments in URI are documented at RFC-3986, Appendix A. The bit we care about in this context is path-abempty

path-abempty  = *( "/" segment )
segment       = *pchar
pchar         = unreserved / pct-encoded / sub-delims / ":" / "@"

So as far as general purpose components (browsers, caches, spiders...) colon is just another letter - it doesn't mean anything more or less than the letter "e" does.

As it happens, the same is true of comma (","), which is a sub-delim.

Now, back in the day, Tim Berners-Lee shared an idea he called Matrix URIs.

Note: relative Matrix URLs are notgenerally implemented so this is just a theoretical discussion. -- TBL

The sample provided looked like:

//moremaps.com/map/color;lat=50;long=20;scale=32000

With the idea that the key value pairs here represent values in a "sparse matrix" of possibilities.

Part of the legacy of matrix URLs is that we have URI Templates using Path Style Parameter Expansion -- which is to say that we have a general purpose way of describing a range of identifiers that include key value pairs like

/map/color{;keys*} 

Which would produce the matrix sample if expanded with a suitable map of values.

For your examples, you would get almost the same result with a slightly different spelling

/fruit{;list*}/price

which would produce your first example if expanded with [banana], and your second example with [banana, mango], except replacing your colon with a semi-colon.

Note that this doesn't tell us anything about meaning; it's a purely mechanical way to expand/extract information in resource identifiers (provided you are willing to abide the spelling constraints).