:relfileprefix: ../../../
[#boost-urls-url_view_base-query]

= xref:boost.adoc[pass:[boost]]::xref:boost/urls.adoc[pass:[urls]]::xref:boost/urls/url_view_base.adoc[pass:[url_view_base]]::query


Return the query


== Synopsis

Declared in header `<https://www.github.com/boostorg/url/blob/develop/include/boost/url/url_view_base.hpp#L1901[boost/url/url_view_base.hpp,window=blank_]>`

[source,cpp,subs="verbatim,macros,-callouts"]
----
template<class StringToken = xref:boost/urls/string_token.adoc[string_token]::xref:boost/urls/string_token/return_string.adoc[return_string]>
StringToken::result_type
query(StringToken&& token) const;
----

== Description


If this contains a query, it is returned
as a string (which may be empty).
Otherwise, an empty string is returned.
Any percent-escapes in the string are
decoded first.


When plus signs appear in the query
portion of the url, they are converted
to spaces automatically upon decoding.
This behavior can be changed by setting
decode options.

=== Example
[,cpp]
----
assert( url_view( "/sql?id=42&name=jane%2Ddoe&page+size=20" ).query() == "id=42&name=jane-doe&page size=20" );
----

=== Complexity

Linear in `this-&gt;query().size()`.

=== Exception Safety

Calls to allocate may throw.

=== BNF
[,cpp]
----
query           = *( pchar / "/" / "?" )

query-param     = key [ "=" value ]
query-params    = [ query-param ] *( "&" query-param )
----

=== Specification

* link:https://datatracker.ietf.org/doc/html/rfc3986#section-3.4
            >3.4.  Query (rfc3986)</a>
        @li <a href=[:&sol;&sol;en.wikipedia.org&sol;wiki&sol;Query_string"            &gt;Query string (Wikipedia)]








== See Also


xref:boost/urls/url_view_base/encoded_params.adoc[encoded_params]
,
xref:boost/urls/url_view_base/encoded_query.adoc[encoded_query]
,
xref:boost/urls/url_view_base/has_query.adoc[has_query]
,
xref:boost/urls/url_view_base/params-05.adoc[params]
.



