< Summary

Information
Class: NanoRoute.NanoRouteQueryExtensions
Assembly: NanoRoute.dll
File(s): /home/runner/work/nanoroute/nanoroute/Src/NanoRoute/Public/Extensions/NanoRouteQueryExtensions.cs
Line coverage
100%
Covered lines: 55
Uncovered lines: 0
Coverable lines: 55
Total lines: 459
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

File(s)

/home/runner/work/nanoroute/nanoroute/Src/NanoRoute/Public/Extensions/NanoRouteQueryExtensions.cs

#LineLine coverage
 1/********************************************************************************
 2* NanoRouteQueryExtensions.cs                                                   *
 3*                                                                               *
 4* Author: Denes Solti                                                           *
 5********************************************************************************/
 6using System;
 7using System.Collections.Generic;
 8using System.Collections.Frozen;
 9using System.Net.Http;
 10
 11namespace NanoRoute
 12{
 13    using Internals;
 14    using Properties;
 15
 16    /// <summary>
 17    /// Defines how query-binding middleware handles query-string parameters that are not declared in the binding descri
 18    /// </summary>
 19    /// <example>
 20    /// <code>
 21    /// builder.AddQueryBindings("{filter:str(min=3)}", unexpected: UnexpectedParameterBehavior.Reject);
 22    /// </code>
 23    /// </example>
 24    public enum UnexpectedParameterBehavior
 25    {
 26        /// <summary>
 27        /// Ignore undeclared query-string parameters.
 28        /// </summary>
 29        /// <example>
 30        /// <code>
 31        /// builder.AddQueryBindings("{filter:str(min=3)}", unexpected: UnexpectedParameterBehavior.Ignore);
 32        /// </code>
 33        /// </example>
 34        Ignore,
 35
 36        /// <summary>
 37        /// Reject undeclared query-string parameters with a <c>400 Bad Request</c> error.
 38        /// </summary>
 39        /// <example>
 40        /// <code>
 41        /// builder.AddQueryBindings("{filter:str(min=3)}", unexpected: UnexpectedParameterBehavior.Reject);
 42        /// </code>
 43        /// </example>
 44        Reject,
 45
 46        // Dangerous since it lets the caller override parameter values provided by earlier middlewares
 47
 48        //AcceptAsString
 49    }
 50
 51    /// <summary>
 52    /// Adds query-parameter binding helpers to NanoRoute.
 53    /// </summary>
 54    /// <example>
 55    /// <code>
 56    /// builder
 57    ///     .AddDefaultValueParsers()
 58    ///     .AddQueryBindings("{page?:int(min=1)}")
 59    ///     .AddHandler("GET", "/items/", (context, _) =&gt; Results.Ok(context.Parameters));
 60    /// </code>
 61    /// </example>
 62    public static class NanoRouteQueryExtensions
 63    {
 64        #region Private
 65        private static RequestHandlerDelegate CreateHandler(RouteScopeBuilder routeScopeBuilder, string bindings, Unexpe
 166        {
 167            Ensure.NotNull(bindings);
 68
 169            if (!Enum.IsDefined(typeof(UnexpectedParameterBehavior), unexpected))
 170                throw new ArgumentOutOfRangeException(nameof(unexpected));
 71
 172            Dictionary<ReadOnlyMemory<char>, ParameterParser> parsedBindingsTmp = new(ReadOnlyMemoryCharComparer.Instanc
 73
 174            foreach (ParameterDefinition parameterDefinition in DslParser.ParseQueryPattern(bindings))
 175            {
 176                if (!routeScopeBuilder.ValueParsers.TryGetValue(parameterDefinition.ValueParser.Name, out ValueParserReg
 177                    throw new InvalidOperationException
 178                    (
 179                        string.Format(Resources.Culture, Resources.ERR_NO_SUCH_PARSER, parameterDefinition.ValueParser.N
 180                    );
 81
 182                parsedBindingsTmp.Add
 183                (
 184                    parameterDefinition.ParameterName!.AsMemory(),
 185                    new ParameterParser
 186                    (
 187                        parameterDefinition,
 188                        parserRegistration.Parse,
 189                        parserRegistration.BindArguments(parameterDefinition.ValueParser.RawArguments)
 190                    )
 191                );
 192            }
 93
 194            FrozenDictionary<ReadOnlyMemory<char>, ParameterParser> parsedBindings = parsedBindingsTmp.ToFrozenDictionar
 95
 196            return async (RequestContext context, CallNextHandlerDelegate next) =>
 197            {
 198                using QueryStringParser queryStringParser = new(context, parsedBindings, unexpected);
 199
 1100                await queryStringParser.Parse().ConfigureAwait(false);
 1101
 1102                return await next().ConfigureAwait(false);
 1103            };
 1104        }
 105        #endregion
 106
 107        extension<TBuilder>(TBuilder routeScopeBuilder) where TBuilder : RouteScopeBuilder
 108        {
 109            /// <summary>
 110            /// Parses configured query parameters and stores their values in <see cref="RequestContext.Parameters"/>.
 111            /// </summary>
 112            /// <param name="bindings">
 113            /// A query-parameter descriptor such as <c>{filter:str(min=3)}&amp;{page?:int(min=1)}</c>.
 114            /// </param>
 115            /// <returns>The current <paramref name="routeScopeBuilder"/> instance.</returns>
 116            /// <remarks>
 117            /// Parsed query values are written into <see cref="RequestContext.Parameters"/>. If that dictionary
 118            /// already contains the same key because of route binding, JSON binding, or earlier middleware, the
 119            /// query binding overwrites the existing value.
 120            /// This overload uses <see cref="RouteScopeBuilder.CurrentPrefix"/> as the route pattern, so the query-bind
 121            /// middleware is bound to the whole current builder scope for all supported HTTP methods.
 122            /// </remarks>
 123            /// <exception cref="InvalidOperationException">
 124            /// Thrown when <paramref name="bindings"/> references a value parser that is not registered.
 125            /// </exception>
 126            /// <exception cref="ArgumentNullException">Thrown when <paramref name="routeScopeBuilder"/> or <paramref na
 127            /// <exception cref="ArgumentException">Thrown when <paramref name="bindings"/> has invalid query-binding sy
 128            /// <exception cref="HttpRequestException">Thrown during request processing when the query string is invalid
 129            /// <example>
 130            /// <code>
 131            /// builder.AddQueryBindings("{filter?:str}&amp;{page?:int(min=1)}");
 132            /// </code>
 133            /// </example>
 1134            public TBuilder AddQueryBindings(string bindings) => routeScopeBuilder.AddQueryBindings(bindings, Unexpected
 135
 136            /// <summary>
 137            /// Parses configured query parameters and stores their values in <see cref="RequestContext.Parameters"/>.
 138            /// </summary>
 139            /// <param name="bindings">
 140            /// A query-parameter descriptor such as <c>{filter:str(min=3)}&amp;{page?:int(min=1)}</c>.
 141            /// </param>
 142            /// <param name="unexpected">Defines how undeclared query-string parameters are handled.</param>
 143            /// <returns>The current <paramref name="routeScopeBuilder"/> instance.</returns>
 144            /// <exception cref="InvalidOperationException">
 145            /// Thrown when <paramref name="bindings"/> references a value parser that is not registered.
 146            /// </exception>
 147            /// <exception cref="ArgumentNullException">Thrown when <paramref name="routeScopeBuilder"/> or <paramref na
 148            /// <exception cref="ArgumentOutOfRangeException">Thrown when <paramref name="unexpected"/> is not a defined
 149            /// <exception cref="ArgumentException">Thrown when <paramref name="bindings"/> has invalid query-binding sy
 150            /// <exception cref="HttpRequestException">Thrown during request processing when the query string is invalid
 151            /// <example>
 152            /// <code>
 153            /// builder.AddQueryBindings("{filter?:str}&amp;{page?:int(min=1)}", unexpected: UnexpectedParameterBehavior
 154            /// </code>
 155            /// </example>
 156            public TBuilder AddQueryBindings(string bindings, UnexpectedParameterBehavior unexpected) =>
 1157                routeScopeBuilder.AddQueryBindings(HttpVerb.Names, RouteScopeBuilder.CurrentPrefix, bindings, unexpected
 158
 159            /// <summary>
 160            /// Parses configured query parameters and stores their values in <see cref="RequestContext.Parameters"/>.
 161            /// </summary>
 162            /// <param name="verbs">The HTTP methods that activate the query-binding middleware.</param>
 163            /// <param name="bindings">
 164            /// A query-parameter descriptor such as <c>{filter:str(min=3)}&amp;{page?:int(min=1)}</c>.
 165            /// </param>
 166            /// <returns>The current <paramref name="routeScopeBuilder"/> instance.</returns>
 167            /// <remarks>
 168            /// Parsed query values are written into <see cref="RequestContext.Parameters"/>. If that dictionary
 169            /// already contains the same key because of route binding, JSON binding, or earlier middleware, the
 170            /// query binding overwrites the existing value.
 171            /// This overload uses <see cref="RouteScopeBuilder.CurrentPrefix"/> as the route pattern, so the query-bind
 172            /// middleware is bound to the whole current builder scope for the selected HTTP methods.
 173            /// </remarks>
 174            /// <exception cref="InvalidOperationException">
 175            /// Thrown when <paramref name="bindings"/> references a value parser that is not registered.
 176            /// </exception>
 177            /// <exception cref="ArgumentNullException">Thrown when <paramref name="routeScopeBuilder"/>, <paramref name
 178            /// <exception cref="ArgumentException">Thrown when an entry in <paramref name="verbs"/> is not supported or
 179            /// <exception cref="HttpRequestException">Thrown during request processing when the query string is invalid
 180            /// <example>
 181            /// <code>
 182            /// builder.AddQueryBindings(["GET", "HEAD"], "{filter?:str}&amp;{page?:int(min=1)}");
 183            /// </code>
 184            /// </example>
 1185            public TBuilder AddQueryBindings(IEnumerable<string> verbs, string bindings) => routeScopeBuilder.AddQueryBi
 186
 187            /// <summary>
 188            /// Parses configured query parameters and stores their values in <see cref="RequestContext.Parameters"/>.
 189            /// </summary>
 190            /// <param name="verbs">The HTTP methods that activate the query-binding middleware.</param>
 191            /// <param name="bindings">
 192            /// A query-parameter descriptor such as <c>{filter:str(min=3)}&amp;{page?:int(min=1)}</c>.
 193            /// </param>
 194            /// <param name="unexpected">Defines how undeclared query-string parameters are handled.</param>
 195            /// <returns>The current <paramref name="routeScopeBuilder"/> instance.</returns>
 196            /// <exception cref="InvalidOperationException">
 197            /// Thrown when <paramref name="bindings"/> references a value parser that is not registered.
 198            /// </exception>
 199            /// <exception cref="ArgumentNullException">Thrown when <paramref name="routeScopeBuilder"/>, <paramref name
 200            /// <exception cref="ArgumentOutOfRangeException">Thrown when <paramref name="unexpected"/> is not a defined
 201            /// <exception cref="ArgumentException">Thrown when an entry in <paramref name="verbs"/> is not supported or
 202            /// <exception cref="HttpRequestException">Thrown during request processing when the query string is invalid
 203            /// <example>
 204            /// <code>
 205            /// builder.AddQueryBindings(["GET", "HEAD"], "{filter?:str}&amp;{page?:int(min=1)}", unexpected: Unexpected
 206            /// </code>
 207            /// </example>
 208            public TBuilder AddQueryBindings(IEnumerable<string> verbs, string bindings, UnexpectedParameterBehavior une
 1209                routeScopeBuilder.AddQueryBindings(verbs, RouteScopeBuilder.CurrentPrefix, bindings, unexpected);
 210
 211            /// <summary>
 212            /// Parses configured query parameters and stores their values in <see cref="RequestContext.Parameters"/>.
 213            /// </summary>
 214            /// <param name="pattern">
 215            /// The route pattern where the query-binding middleware should be inserted. Use <c>/</c> to apply it to
 216            /// the whole pipeline, or a narrower prefix/exact pattern to scope query binding to selected routes.
 217            /// </param>
 218            /// <param name="bindings">
 219            /// A query-parameter descriptor such as <c>{filter:str(min=3)}&amp;{page?:int(min=1)}</c>.
 220            /// </param>
 221            /// <returns>The current <paramref name="routeScopeBuilder"/> instance.</returns>
 222            /// <remarks>
 223            /// Parsed query values are written into <see cref="RequestContext.Parameters"/>. If that dictionary
 224            /// already contains the same key because of route binding, JSON binding, or earlier middleware, the
 225            /// query binding overwrites the existing value.
 226            /// </remarks>
 227            /// <exception cref="InvalidOperationException">
 228            /// Thrown when <paramref name="bindings"/> references a value parser that is not registered.
 229            /// </exception>
 230            /// <exception cref="ArgumentNullException">Thrown when <paramref name="routeScopeBuilder"/>, <paramref name
 231            /// <exception cref="ArgumentException">Thrown when <paramref name="pattern"/> has invalid route-template sy
 232            /// <exception cref="HttpRequestException">Thrown during request processing when the query string is invalid
 233            /// <example>
 234            /// <code>
 235            /// builder.AddQueryBindings("/items/*", "{filter?:str}&amp;{page?:int(min=1)}");
 236            /// </code>
 237            /// </example>
 1238            public TBuilder AddQueryBindings(string pattern, string bindings) => routeScopeBuilder.AddQueryBindings(patt
 239
 240            /// <summary>
 241            /// Parses configured query parameters and stores their values in <see cref="RequestContext.Parameters"/>.
 242            /// </summary>
 243            /// <param name="pattern">
 244            /// The route pattern where the query-binding middleware should be inserted. Use <c>/</c> to apply it to
 245            /// the whole pipeline, or a narrower prefix/exact pattern to scope query binding to selected routes.
 246            /// </param>
 247            /// <param name="bindings">
 248            /// A query-parameter descriptor such as <c>{filter:str(min=3)}&amp;{page?:int(min=1)}</c>.
 249            /// </param>
 250            /// <param name="unexpected">Defines how undeclared query-string parameters are handled.</param>
 251            /// <returns>The current <paramref name="routeScopeBuilder"/> instance.</returns>
 252            /// <exception cref="InvalidOperationException">
 253            /// Thrown when <paramref name="bindings"/> references a value parser that is not registered.
 254            /// </exception>
 255            /// <exception cref="ArgumentNullException">Thrown when <paramref name="routeScopeBuilder"/>, <paramref name
 256            /// <exception cref="ArgumentOutOfRangeException">Thrown when <paramref name="unexpected"/> is not a defined
 257            /// <exception cref="ArgumentException">Thrown when <paramref name="pattern"/> has invalid route-template sy
 258            /// <exception cref="HttpRequestException">Thrown during request processing when the query string is invalid
 259            /// <example>
 260            /// <code>
 261            /// builder.AddQueryBindings("/items/*", "{filter?:str}&amp;{page?:int(min=1)}", unexpected: UnexpectedParam
 262            /// </code>
 263            /// </example>
 264            public TBuilder AddQueryBindings(string pattern, string bindings, UnexpectedParameterBehavior unexpected) =>
 1265                routeScopeBuilder.AddQueryBindings(HttpVerb.Names, pattern, bindings, unexpected);
 266
 267            /// <summary>
 268            /// Parses configured query parameters and stores their values in <see cref="RequestContext.Parameters"/>.
 269            /// </summary>
 270            /// <param name="verb">The HTTP method that activates the query-binding middleware.</param>
 271            /// <param name="pattern">
 272            /// The route pattern where the query-binding middleware should be inserted. Use <c>/</c> to apply it to
 273            /// the whole pipeline, or a narrower prefix/exact pattern to scope query binding to selected routes.
 274            /// </param>
 275            /// <param name="bindings">
 276            /// A query-parameter descriptor such as <c>{filter:str(min=3)}&amp;{page?:int(min=1)}</c>.
 277            /// </param>
 278            /// <returns>The current <paramref name="routeScopeBuilder"/> instance.</returns>
 279            /// <remarks>
 280            /// Parsed query values are written into <see cref="RequestContext.Parameters"/>. If that dictionary
 281            /// already contains the same key because of route binding, JSON binding, or earlier middleware, the
 282            /// query binding overwrites the existing value.
 283            /// </remarks>
 284            /// <exception cref="InvalidOperationException">
 285            /// Thrown when <paramref name="bindings"/> references a value parser that is not registered.
 286            /// </exception>
 287            /// <exception cref="ArgumentNullException">Thrown when <paramref name="routeScopeBuilder"/>, <paramref name
 288            /// <exception cref="ArgumentException">Thrown when <paramref name="verb"/> is not supported, <paramref name
 289            /// <exception cref="HttpRequestException">Thrown during request processing when the query string is invalid
 290            /// <example>
 291            /// <code>
 292            /// builder.AddQueryBindings("GET", "/items/*", "{filter?:str}&amp;{page?:int(min=1)}");
 293            /// </code>
 294            /// </example>
 1295            public TBuilder AddQueryBindings(string verb, string pattern, string bindings) => routeScopeBuilder.AddQuery
 296
 297            /// <summary>
 298            /// Parses configured query parameters and stores their values in <see cref="RequestContext.Parameters"/>.
 299            /// </summary>
 300            /// <param name="verb">The HTTP method that activates the query-binding middleware.</param>
 301            /// <param name="pattern">
 302            /// The route pattern where the query-binding middleware should be inserted. Use <c>/</c> to apply it to
 303            /// the whole pipeline, or a narrower prefix/exact pattern to scope query binding to selected routes.
 304            /// </param>
 305            /// <param name="bindings">
 306            /// A query-parameter descriptor such as <c>{filter:str(min=3)}&amp;{page?:int(min=1)}</c>.
 307            /// </param>
 308            /// <param name="unexpected">Defines how undeclared query-string parameters are handled.</param>
 309            /// <returns>The current <paramref name="routeScopeBuilder"/> instance.</returns>
 310            /// <exception cref="InvalidOperationException">
 311            /// Thrown when <paramref name="bindings"/> references a value parser that is not registered.
 312            /// </exception>
 313            /// <exception cref="ArgumentNullException">Thrown when <paramref name="routeScopeBuilder"/>, <paramref name
 314            /// <exception cref="ArgumentOutOfRangeException">Thrown when <paramref name="unexpected"/> is not a defined
 315            /// <exception cref="ArgumentException">Thrown when <paramref name="verb"/> is not supported, <paramref name
 316            /// <exception cref="HttpRequestException">Thrown during request processing when the query string is invalid
 317            /// <example>
 318            /// <code>
 319            /// builder.AddQueryBindings("GET", "/items/*", "{filter?:str}&amp;{page?:int(min=1)}", unexpected: Unexpect
 320            /// </code>
 321            /// </example>
 322            public TBuilder AddQueryBindings(string verb, string pattern, string bindings, UnexpectedParameterBehavior u
 1323                routeScopeBuilder.AddQueryBindings([verb /*will be null checked*/], pattern, bindings, unexpected);
 324
 325            /// <summary>
 326            /// Parses configured query parameters and stores their values in <see cref="RequestContext.Parameters"/>.
 327            /// </summary>
 328            /// <param name="verbs">The HTTP methods that activate the query-binding middleware.</param>
 329            /// <param name="pattern">
 330            /// The route pattern where the query-binding middleware should be inserted. Use <c>/</c> to apply it to
 331            /// the whole pipeline, or a narrower prefix/exact pattern to scope query binding to selected routes.
 332            /// </param>
 333            /// <param name="bindings">
 334            /// A query-parameter descriptor such as <c>{filter:str(min=3)}&amp;{page?:int(min=1)}</c>.
 335            /// </param>
 336            /// <returns>The current <paramref name="routeScopeBuilder"/> instance.</returns>
 337            /// <remarks>
 338            /// Parsed query values are written into <see cref="RequestContext.Parameters"/>. If that dictionary
 339            /// already contains the same key because of route binding, JSON binding, or earlier middleware, the
 340            /// query binding overwrites the existing value.
 341            /// </remarks>
 342            /// <exception cref="InvalidOperationException">
 343            /// Thrown when <paramref name="bindings"/> references a value parser that is not registered.
 344            /// </exception>
 345            /// <exception cref="ArgumentNullException">Thrown when <paramref name="routeScopeBuilder"/>, <paramref name
 346            /// <exception cref="ArgumentException">Thrown when an entry in <paramref name="verbs"/> is not supported, <
 347            /// <exception cref="HttpRequestException">Thrown during request processing when the query string is invalid
 348            /// <example>
 349            /// <code>
 350            /// builder.AddQueryBindings(["GET", "HEAD"], "/items/*", "{filter?:str}&amp;{page?:int(min=1)}");
 351            /// </code>
 352            /// </example>
 353            public TBuilder AddQueryBindings(IEnumerable<string> verbs, string pattern, string bindings) =>
 1354                routeScopeBuilder.AddQueryBindings(verbs, pattern, bindings, UnexpectedParameterBehavior.Ignore);
 355
 356            /// <summary>
 357            /// Parses configured query parameters and stores their values in <see cref="RequestContext.Parameters"/>.
 358            /// </summary>
 359            /// <param name="verbs">The HTTP methods that activate the query-binding middleware.</param>
 360            /// <param name="pattern">
 361            /// The route pattern where the query-binding middleware should be inserted. Use <c>/</c> to apply it to
 362            /// the whole pipeline, or a narrower prefix/exact pattern to scope query binding to selected routes.
 363            /// </param>
 364            /// <param name="bindings">
 365            /// A query-parameter descriptor such as <c>{filter:str(min=3)}&amp;{page?:int(min=1)}</c>.
 366            /// </param>
 367            /// <param name="unexpected">Defines how undeclared query-string parameters are handled.</param>
 368            /// <returns>The current <paramref name="routeScopeBuilder"/> instance.</returns>
 369            /// <remarks>
 370            /// Parsed query values are written into <see cref="RequestContext.Parameters"/>. If that dictionary
 371            /// already contains the same key because of route binding, JSON binding, or earlier middleware, the
 372            /// query binding overwrites the existing value.
 373            /// </remarks>
 374            /// <exception cref="InvalidOperationException">
 375            /// Thrown when <paramref name="bindings"/> references a value parser that is not registered.
 376            /// </exception>
 377            /// <exception cref="ArgumentNullException">Thrown when <paramref name="routeScopeBuilder"/>, <paramref name
 378            /// <exception cref="ArgumentOutOfRangeException">Thrown when <paramref name="unexpected"/> is not a defined
 379            /// <exception cref="ArgumentException">Thrown when an entry in <paramref name="verbs"/> is not supported, <
 380            /// <exception cref="HttpRequestException">Thrown during request processing when the query string is invalid
 381            /// <example>
 382            /// <code>
 383            /// builder.AddQueryBindings(["GET", "HEAD"], "/items/*", "{filter?:str}&amp;{page?:int(min=1)}", unexpected
 384            /// </code>
 385            /// </example>
 386            public TBuilder AddQueryBindings(IEnumerable<string> verbs, string pattern, string bindings, UnexpectedParam
 1387            {
 1388                Ensure.NotNull(routeScopeBuilder);
 1389                Ensure.NotNull(verbs);
 1390                Ensure.NotNull(pattern);
 391
 1392                routeScopeBuilder.AddHandler(verbs, pattern, CreateHandler(routeScopeBuilder, bindings, unexpected));
 393
 1394                return routeScopeBuilder;
 395            }
 396        }
 397
 398        extension(EndpointBuilder endpointBuilder)
 399        {
 400            /// <summary>
 401            /// Parses configured query parameters and stores their values in <see cref="RequestContext.Parameters"/>
 402            /// for the current endpoint.
 403            /// </summary>
 404            /// <param name="bindings">
 405            /// A query-parameter descriptor such as <c>{filter:str(min=3)}&amp;{page?:int(min=1)}</c>.
 406            /// </param>
 407            /// <returns>The current <paramref name="endpointBuilder"/> instance.</returns>
 408            /// <remarks>
 409            /// The query-binding middleware is registered for the endpoint's captured HTTP methods and route match
 410            /// kind. Parsed query values are written into <see cref="RequestContext.Parameters"/>. If that dictionary
 411            /// already contains the same key because of route binding, JSON binding, or earlier middleware, the
 412            /// query binding overwrites the existing value.
 413            /// </remarks>
 414            /// <exception cref="InvalidOperationException">
 415            /// Thrown when <paramref name="bindings"/> references a value parser that is not registered.
 416            /// </exception>
 417            /// <exception cref="ArgumentNullException">Thrown when <paramref name="endpointBuilder"/> or <paramref name
 418            /// <exception cref="ArgumentException">Thrown when the endpoint's captured HTTP method is not supported or 
 419            /// <exception cref="HttpRequestException">Thrown during request processing when the query string is invalid
 420            /// <example>
 421            /// <code>
 422            /// endpoint.WithQueryBindings("{filter?:str}&amp;{page?:int(min=1)}");
 423            /// </code>
 424            /// </example>
 1425            public EndpointBuilder WithQueryBindings(string bindings) => endpointBuilder.WithQueryBindings(bindings, Une
 426
 427            /// <summary>
 428            /// Parses configured query parameters and stores their values in <see cref="RequestContext.Parameters"/>
 429            /// for the current endpoint.
 430            /// </summary>
 431            /// <param name="bindings">
 432            /// A query-parameter descriptor such as <c>{filter:str(min=3)}&amp;{page?:int(min=1)}</c>.
 433            /// </param>
 434            /// <param name="unexpected">Defines how undeclared query-string parameters are handled.</param>
 435            /// <returns>The current <paramref name="endpointBuilder"/> instance.</returns>
 436            /// <exception cref="InvalidOperationException">
 437            /// Thrown when <paramref name="bindings"/> references a value parser that is not registered.
 438            /// </exception>
 439            /// <exception cref="ArgumentNullException">Thrown when <paramref name="endpointBuilder"/> or <paramref name
 440            /// <exception cref="ArgumentOutOfRangeException">Thrown when <paramref name="unexpected"/> is not a defined
 441            /// <exception cref="ArgumentException">Thrown when the endpoint's captured HTTP method is not supported or 
 442            /// <exception cref="HttpRequestException">Thrown during request processing when the query string is invalid
 443            /// <example>
 444            /// <code>
 445            /// endpoint.WithQueryBindings("{filter?:str}&amp;{page?:int(min=1)}", unexpected: UnexpectedParameterBehavi
 446            /// </code>
 447            /// </example>
 448            public EndpointBuilder WithQueryBindings(string bindings, UnexpectedParameterBehavior unexpected)
 1449            {
 1450                Ensure.NotNull(endpointBuilder);
 451
 1452                return endpointBuilder.WithHandler
 1453                (
 1454                    CreateHandler(endpointBuilder.Prefix, bindings, unexpected)
 1455                );
 456            }
 457        }
 458    }
 459}