mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-17 22:14:26 +01:00
API: Add health check endpoint
This commit is contained in:
15
BTCPayServer.Client/BTCPayServerClient.Health.cs
Normal file
15
BTCPayServer.Client/BTCPayServerClient.Health.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
16
BTCPayServer/Controllers/GreenField/HealthController.cs
Normal file
16
BTCPayServer/Controllers/GreenField/HealthController.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
26
BTCPayServer/wwwroot/swagger/v1/swagger.template.health.json
Normal file
26
BTCPayServer/wwwroot/swagger/v1/swagger.template.health.json
Normal 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"
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user