Skip to content

Instantly share code, notes, and snippets.

@anytizer
Last active November 13, 2025 10:53
Show Gist options
  • Select an option

  • Save anytizer/3013f343eaaff7308957788d3d4d9a9a to your computer and use it in GitHub Desktop.

Select an option

Save anytizer/3013f343eaaff7308957788d3d4d9a9a to your computer and use it in GitHub Desktop.
Debug Listing of registered Web APIs
using Microsoft.AspNetCore.Mvc;
namespace web.Controllers
{
public class EndPointDTO
{
public string? name { get; set; }
public string? pattern { get; set; }
public List<string>? methods { get; set; }
}
[ApiController]
[Route("api/[controller]")]
public class DebugController : ControllerBase
{
private readonly IEnumerable<EndpointDataSource> _endpointSources;
public DebugController(IEnumerable<EndpointDataSource> endpointSources)
{
_endpointSources = endpointSources;
}
// http[s]://localhost:<PORT>/api/debug/endpoints
[HttpGet("endpoints")]
public List<EndPointDTO> GetEndpoints()
{
List<EndPointDTO> endpoints = new List<EndPointDTO>();
var allEndpoints = _endpointSources.SelectMany(es => es.Endpoints);
foreach (var ep in allEndpoints)
{
EndPointDTO endpoint = new EndPointDTO()
{
name = ep.DisplayName,
pattern = (ep as RouteEndpoint)?.RoutePattern?.RawText,
methods = ep.Metadata.OfType<HttpMethodMetadata>().FirstOrDefault()?.HttpMethods.ToList(),
};
endpoints.Add(endpoint);
}
return endpoints;
}
}
}
using Microsoft.AspNetCore.Mvc;
namespace web.Controllers
{
[ApiController]
[Route("api/[controller]")]
public class DebugController : ControllerBase
{
private readonly IEnumerable<EndpointDataSource> _endpointSources;
public DebugController(IEnumerable<EndpointDataSource> endpointSources)
{
_endpointSources = endpointSources;
}
// http[s]://localhost:<PORT>/api/debug/endpoints
[HttpGet("endpoints2")]
public List<string> GetEndpoints()
{
List<string> endpoints = new List<string>();
var allEndpoints = _endpointSources.SelectMany(es => es.Endpoints);
foreach (var ep in allEndpoints)
{
string endpoint = (ep as RouteEndpoint)?.RoutePattern?.RawText;
endpoints.Add(endpoint);
}
return endpoints;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment