title: How to handle multiple endpoints in ASP.Net Core 3 Web API properly
body: <p>I have 2 methods to handle HTTP GET requests, first one for <code>int</code> type input and the other one for <code>string</code> type input.</p>
  
  <pre><code>//GET : api/Fighters/5
  [HttpGet("{id}")]
  public async Task&lt;ActionResult&lt;Fighter&gt;&gt; GetFighter(int id) 
  {
      var fighter = await _context.Fighters.FindAsync(id);
  
      if (fighter == null) 
      {
          return NotFound();
      }
      return fighter;
  }
  
  // GET: api/Fighters/Alex
  [Route("api/Fighters/{name}")]
  [HttpGet("{name}")]
  public async Task&lt;ActionResult&lt;IEnumerable&lt;Fighter&gt;&gt;&gt; GetFighter (string name) 
  {
      return await _context.Fighters.Where(f =&gt; f.Name == name).ToListAsync();
  }
  </code></pre>
  
  <p>when i send HTTP GET this exception appears (in Postman):</p>
  
  <pre><code>Microsoft.AspNetCore.Routing.Matching.AmbiguousMatchException: The request matched multiple endpoints. Matches: 
  
  FighterGameService.Controllers.FightersController.GetFighter (FighterGameService)
  FighterGameService.Controllers.FightersController.GetFighter (FighterGameService)
  FighterGameService.Controllers.FightersController.GetFighter (FighterGameService)
  FighterGameService.Controllers.FightersController.GetFighter (FighterGameService)
     at Microsoft.AspNetCore.Routing.Matching.DefaultEndpointSelector.ReportAmbiguity(CandidateState[] candidateState)
     at Microsoft.AspNetCore.Routing.Matching.DefaultEndpointSelector.ProcessFinalCandidates(HttpContext httpContext, CandidateState[] candidateState)
     at Microsoft.AspNetCore.Routing.Matching.DefaultEndpointSelector.Select(HttpContext httpContext, CandidateState[] candidateState)
     at Microsoft.AspNetCore.Routing.Matching.DfaMatcher.MatchAsync(HttpContext httpContext)
     at Microsoft.AspNetCore.Routing.Matching.DataSourceDependentMatcher.MatchAsync(HttpContext httpContext)
     at Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware.Invoke(HttpContext httpContext)
     at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)
     at Microsoft.AspNetCore.HttpsPolicy.HttpsRedirectionMiddleware.Invoke(HttpContext context)
     at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
  </code></pre>
  
  <p><code>GET api/fighters/1</code> would cause error obviously since "<code>1</code>" could be either <code>int</code> or <code>string</code> so i solved my problem by combining two methods:</p>
  
  <pre><code>// GET: api/Fighters/5
  // GET: api/Fighters/Alex
  [HttpGet("{idOrName}")]
  public async Task&lt;ActionResult&lt;IEnumerable&lt;Fighter&gt;&gt;&gt; GetFighter(string idOrName)
  {
      if (Int32.TryParse(idOrName, out int id))
      {
          return await _context.Fighters.Where(f =&gt; f.Id == id).ToListAsync();
      }
      else
      {
          return await _context.Fighters.Where(f =&gt; f.Name == idOrName).ToListAsync();
      }
  
  }
  </code></pre>
  
  <p>this works however this doesn't feel right at all. What is the proper way to handle this problem?</p>