[Feature] REST API Endpoint

This commit is contained in:
2025-04-15 15:51:57 +02:00
parent 41f88e60ae
commit d65ce09aea
3 changed files with 27 additions and 2 deletions

View File

@@ -1,2 +1,10 @@
# TemplateNETService
Template for windows service based on .net 8 with the following features:
- Log with Serilog
- Example to extract configuration settings from appsettings.json and safe in static class "Config"
- OnStart & OnStop functions (File: BaseWorker.cs)
- Batch files to install / delete service
- Example for an API-Endpoint: api/ping (File: ServiceController.cs)

View File

@@ -5,6 +5,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TemplateNETService.Business;
namespace TemplateNETService
{
@@ -12,7 +13,7 @@ namespace TemplateNETService
{
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
Log.Debug("Der Service wurde gestartet.");
Log.Debug($"Service is started on port {Config.general.ThisPort}...");
while (!stoppingToken.IsCancellationRequested)
{
@@ -23,7 +24,7 @@ namespace TemplateNETService
public override async Task StopAsync(CancellationToken cancellationToken)
{
Log.Debug("Der Service wird gestoppt.");
Log.Debug("Service stopped...");
}
}
}

View File

@@ -0,0 +1,16 @@
using Microsoft.AspNetCore.Mvc;
namespace TemplateNETService.Controllers
{
[ApiController]
[Route("api")]
public class ServiceController : ControllerBase
{
[HttpGet]
[Route("ping")]
public IActionResult GetStatus()
{
return Ok();
}
}
}