I'm using a health checkup strategy that returns a certaing pong while I ping on the following URL.
localhost/util/ping
This works as supposed to. Then, I was considering that a lazy user might miss to type in util or pehaps get confused typing utils, utility or utilities. That can be frustrating, especially for new developers, who don't know of Swagger.
localhost/ping
So I decided to introduce a dedicated pseudo route only containing ping aiming at the URL above. There are no other routes (except the default one) nor controllers with the name that would collide, as far I can see.
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "ping",
pattern: "ping",
defaults: new { controller = "util", action = "ping" });
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller}/{action=Index}/{id?}");
});
Regrettably, the above code doesn't seem to work. It produces status code 404 and I can't see what I'm missing that could differ from the example in MSDN.
The controller is declared as follows.
namespace Api.Controllers
{
[ApiController]
[Route("[controller]")]
public class UtilController : ControllerBase
{
[HttpGet("ping")]
public ActionResult Ping() { return Ok("pong"); }
}
}
