API: Add health check endpoint

This commit is contained in:
Dennis Reimann
2020-04-16 15:39:08 +02:00
parent 0a1a4fd3b5
commit 3bd5c3e1b5
4 changed files with 71 additions and 0 deletions

View File

@@ -0,0 +1,15 @@
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
namespace BTCPayServer.Client
{
public partial class BTCPayServerClient
{
public virtual async Task<bool> IsHealthy(CancellationToken token = default)
{
var response = await _httpClient.SendAsync(CreateHttpRequest("api/v1/health"), token);
return response.IsSuccessStatusCode;
}
}
}

View File

@@ -228,5 +228,19 @@ namespace BTCPayServer.Tests
}
}
[Fact(Timeout = TestTimeout)]
[Trait("Integration", "Integration")]
public async Task HealthControllerTests()
{
using (var tester = ServerTester.Create())
{
await tester.StartAsync();
var unauthClient = new BTCPayServerClient(tester.PayTester.ServerUri);
var isHealthy = await unauthClient.IsHealthy();
Assert.True(isHealthy);
}
}
}
}

View File

@@ -0,0 +1,16 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace BTCPayServer.Controllers.GreenField
{
[ApiController]
public class HealthController : ControllerBase
{
[AllowAnonymous]
[HttpGet("~/api/v1/health")]
public ActionResult GetHealth()
{
return Ok();
}
}
}

View File

@@ -0,0 +1,26 @@
{
"paths": {
"/api/v1/health": {
"get": {
"tags": [
"Health"
],
"summary": "Get health status",
"description": "Check whether of not the instance is up",
"operationId": "Health_GetHealth",
"responses": {
"200": {
"description": "Instance is up",
"content": {}
}
},
"security": []
}
}
},
"tags": [
{
"name": "Health"
}
]
}