URL Path Parameter Use Cases

后端 未结 2 2109
失恋的感觉
失恋的感觉 2021-02-13 01:56

Normally when I think of parameters in an URL, I think of the query string. Technically, however, it is also legal to specify parameters in the path segments. Thus given a URL

2条回答
  •  爱一瞬间的悲伤
    2021-02-13 02:27

    Many modern framework will support specifying variables as part of a path segment, in their URL-parsing systems.

    Symfony (PHP) and Django (Python) would both support this as they support extracting values from URLs via regular expressions.

    One significant difference is that parameters specified in the query string can usually be in any order, because they will typically be parsed into a dictionary-like structure. That wouldn't apply to parameters in a path segment. You could of course parse them yourself into a dictionary, but the frameworks I just mentioned won't help you do that.

    Note that technically the order of the parameters is significant in an HTTP URI anyway, i.e. a conforming comparison of two URLs where the parameters (in the path or in the query string) were in a different order would have to assume that they could reference a different resource.

提交回复
热议问题