NetCoreUsefullEndpoints-part 8- adding start date
In my NuGet NetCoreUsefullEndpoints package I have had already registered the actual date as
var rh = route.MapGet(“api/usefull/dateUTC”, (HttpContext httpContext) =>
{
return Results.Ok(DateTime.UtcNow);
});
Now I want to register also the start date – the date where the application has been started.
1. How to do this ?
2. What will be the route ?
For 1 can be a static constructor or, better , the singleton in C# :
private static DateTime startDateUTC = DateTime.UtcNow;
For 2 it is more complicated
My solution ( just break compatibility, since I have not a v1 and v2) was the following
var rh = route.MapGet(“api/usefull/date/startUTC”, (HttpContext httpContext) =>
{
return Results.Ok(startDateUTC);
});var rhUTC = route.MapGet(“api/usefull/date/nowUTC/”,
(HttpContext httpContext) =>
{
return TypedResults.Ok(DateTime.UtcNow);
});rhUTC.AddDefault(corsPolicy, authorization);
So now I have same routing api/usefull/date
Leave a Reply