Web API optional parameters
<p>I have a controller with the following signature:</p>

<pre><code>[Route("products/filter/{apc=apc}/{xpc=xpc}/{sku=sku}")]
public IHttpActionResult Get(string apc, string xpc, int? sku)
{ ... }
</code></pre>

<p>I call this method with following URIs:</p>

<ul>
<li>~/api/products/filter?apc=AA&amp;xpc=BB</li>
<li>~/api/products/filter?sku=7199123</li>
</ul>

<p>The first URI works without issue. The second one has a strange side effect. Even though the default values for apc and xpc should be null when not provided, the parameters are actually their names. I can overcome this by adding the additional logic:</p>

<pre><code>apc = (apc == "apc") ? null : apc;
xpc = (xpc == "xpc") ? null : xpc;
</code></pre>

<p>This seems like a hack, and would be problematic if value passed was ever equal to the parameter name. </p>

<p>Is there a way to define the Route without this side effect? </p>