Temporary Pause
I am using .NET 8
I've got an ASP.NET API that i would like to pause. The goal of this is to prevent any endpoints from being called for a short amount of time. I could do this procedurally with a constant variable that's checked, but I would rather not send nothing.
Is there some kind of HTML code i could return that would indicate that the API is offline but like on purpose? Instead of just returning nothing.
I also need a way to return this response to the user when they try to access the API while its paused. Is there a way for be to disable all the endpoints and run a default endpoint?
4 Replies
I'd do it via a middleware
If API access is paused, return the info about that
If it's not, continue
As for the status code... 503 Service Unavailable maybe?
https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/503
Great. How do i add that code to the response? atm i just am returning a result from a method if registered with a
WebApplication.MapGet()
(or the relivent MapSomthing). How do i manipulate the HTTP responce?As I said, easiest way to handle it would be a middleware
Some
thats perfict. thanks!