'How log or get api reference on [DOTNET CORE WEB APP] before removing it without knowing its api without knowing its reference
Due to separate controllers for GET and POST method or there can be multiple reasons that cause duplicate API as per use case scenario what if the next developer ditch that API without knowing its reference, What will be the possible ways to prevent it, How to log or find its reference [DOTNET CORE WEB APP]
Constant
public static class EndpointsConstant
{
public const string Greet = "/Home/Greet";
}
customAttribute
public class UsagesLogAttribute : Attribute
{
public UsagesLogAttribute(string apiEndpoints)
{
Console.WriteLine(apiEndpoints);
}
}
Adding Reference
[UsagesLog(EndpointsConstant.Greet)]
public IActionResult Greet() => new JsonResult(new { message = "Hello World" });
Index.cshtml
@using test.Constants
@{
ViewData["Title"] = "Home Page";
}
@section Scripts
{
<script>
document.addEventListener('DOMContentLoaded',async ()=>{
const response = await fetch('@EndpointsConstant.Greet').then(res=>res.json());
document.body.appendChild(document.createTextNode(response.message));
});
</script>
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
