title: ASP.NET Core API - Dynamic Routing (Make API route behave like "one-parameter query string")
body: <p>Aloha :D
  I would like to create a dynamic route binding.
  What I mean by this, is basically replacing the Query String with a dynamic route.</p>
  
  <p>Example:
  Instead of this: </p>
  
  <pre><code>POST http://localhost:5000/api/documents?templatename=individualemploymentagreement
  </code></pre>
  
  <p>this:            </p>
  
  <pre><code>POST http://localhost:5000/api/documents/individualemploymentagreement
  </code></pre>
  
  <p><strong>Note:</strong> after "<a href="http://localhost:5000/api/documents/" rel="nofollow noreferrer">http://localhost:5000/api/documents/</a>" I want to put anything I want, but this route will always be used and what comes after should be used like a variable. Obviously, this will lead to a non-existing API Route at the moment. But is there any way to deal with this?</p>
  
  <p><strong>Note 2:</strong> The reasons I want to use this are:
  - According to RESTful services "rules", query strings should be used just for queries, In this case I'm not using a query, I'm calling a generic document service, which however, treats every document slightly different when needed. So query strings are not recommended in my case.
  - This service will deal with hundreds of document types, so I can't really make a different path / api for each one of them. So this is not recommended as well.</p>
  
  <p><strong>My code</strong> (In which I'm using a query string for {templateName}:</p>
  
  <pre><code>namespace DocumentGenerator.Api.Controllers
  {
      [Route("api/{controller}")]
      [ApiController]
      public class DocumentsController : ControllerBase
      {
        //useless details
  
          [HttpPost]  
          public async Task&lt;IActionResult&gt; Generate([FromQuery] string templateName, [FromBody] object properties)
          {
              // according to {templateName} do this or that...
              // useless details
          }
       }
  }
  </code></pre>
  
  <p><strong>What I would want in code</strong>:</p>
  
  <pre><code> namespace DocumentGenerator.Api.Controllers
      {
          [Route("api/{controller}")]
          [ApiController]
          public class DocumentsController : ControllerBase
          {
            //useless details
  
              [HttpPost("{templateName}"]  
              public async Task&lt;IActionResult&gt; Generate([FromBody] object properties)
              {
                  // according to {templateName} do this or that...
                  // useless details
              }
           }
      }
  </code></pre>