Vaultools
Menu

Query string

The query string is the part of a URL after the "?" and before any "#", made of key=value pairs joined by "&", used to pass parameters to a page or API. Its format is a convention layered on top of the URL standard, not one strict specification.

Anatomy of a URL

https://shop.example.com:8443/search/wine?q=caf%C3%A9&tag=a&tag=b#results
\___/   \_______________/\___/\_________/ \____________________/ \_____/
scheme       host        port    path            query           fragment

The query starts at the first ? and ends at the first #. The fragment after it is handled by the browser and is never sent to the server, so a ? that appears inside the fragment is not part of the query.

Pairs, keys and values

By convention the query is a list of key=value pairs separated by &. Each key and value is percent-encoded, and a + usually stands for a space. Several details vary:

Reading and building one

In JavaScript, new URL(text).searchParams reads a query and searchParams.set('q', value) writes one, encoding correctly as it goes. In Python, urllib.parse.parse_qs and urlencode do the same. Building a query by string concatenation is where most encoding bugs come from.

Common pitfalls

References

Ads on this page

Non-personalized ads help keep Vaultools free — Google decides where they appear on the page.

Go Pro to remove them →