whatwg / url

URL Standard
https://url.spec.whatwg.org/
Other
535 stars 139 forks source link

The web needs a stable definition of a Query Parameter in a URL #617

Open roger-on-github opened 3 years ago

roger-on-github commented 3 years ago

There are many, many APIs and network protocols that require the use of URL query parameters (http://example.com/resource?a=b&c=d). But I have not been able to find an authoritative definition of the term in any spec. Most URL specs go as far as defining the query part of the URL and its allowed character set, but stop short of defining its use as a list of key+value pairs.

It would be enormously helpful if a definition for query parameters could be added to the whatwg URL spec.

mnot commented 3 years ago

Hi Roger,

It's specified in the URL spec, here.

That format isn't actually fixed across all URLs -- or even all HTTP URLs. It was originally defined by HTTP and then migrated into the URL spec later. Furthermore, the URL specification doesn't (yet) specify syntax; only parsing algorithms. For the syntax, RFC3986 is authoritative (although there are some small differences between the two specs).

roger-on-github commented 3 years ago

application/x-www-form-urlencoded specifies something, but nowhere is it matched with a defined term of a "query parameter" - so it's not helpful from a normative reference standpoint.

RFC3986 likewise defines the query component, and even makes passing reference to key=value pairs, but likewise does not define a "query parameter" or the rules for composing or parsing one.

mnot commented 3 years ago

Yes - because the query string of an URL can be in any format that conforms to the 3986 syntax - this is just one -- albeit extremely common -- option.

roger-on-github commented 3 years ago

Agreed. And it is my point that it would be helpful if something codified this extremely common option for the purposes of common reference.

mnot commented 3 years ago

Specifically, are you arguing that there should be a formal grammar, as well as a parsing algorithm?

roger-on-github commented 3 years ago

I don't know what would fit best within the whatwg URL spec, but yes, I'm suggesting that somewhere there be language along the lines of "A URL-query-string MAY be composed of a set of URL-query-parameters separated by &, A URL-query-parameter has the following syntax, etc."

annevk commented 3 years ago

It seems somewhat reasonable to link from https://url.spec.whatwg.org/#concept-url-query to https://url.spec.whatwg.org/#concept-urlencoded-string-parser in a note or so. I'm not sure we'd want to say anything normative though.

bergus commented 1 year ago

Sounds like a duplicate of #491?

I also wondered how the official term "query string" lead to URLSearchParams

annevk commented 1 year ago

It's not a duplicate, see the comment right before yours. (As for terminology, "search" has been the API term for "query" on the web since forever.)