Last active
November 13, 2025 10:53
-
-
Save anytizer/3013f343eaaff7308957788d3d4d9a9a to your computer and use it in GitHub Desktop.
Debug Listing of registered Web APIs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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