Documentation

Implement HTTP API Services in Nomirun modules

ASP.NET HTTP Controllers are implemented the way you know it. The only difference is that you need to inherit your controller from NomirunApiController class.

When you create a new module, the sample controller is located in the src/Infrastructure/HttpApi folder.

Here is an example:

using Nomirun.Sdk.Abstractions.Interfaces;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Nomirun.Sdk.Abstractions;

namespace CustomerModule.Infrastructure.HttpApi.v1;

[Route("api")]
public class CustomerModuleController : NomirunApiController
{
    private readonly ILogger<CustomerModuleController> _logger;
    private readonly IHttpClientService _service;

    public CustomerModuleController(ILogger<CustomerModuleController> logger, IHttpClientService service) : base(logger)
    {
        _logger = logger;
        _service = service;
    }

    [HttpGet("demo")]
    public async Task<IActionResult> DemoAction()
    {
        var result = await _service
        .CreateHttpRequest(new Uri("https://google.com"))
        .WithMethod(HttpMethod.Get)
        .Start();

        return Ok(result.StatusCode.ToString());
    }
}

Your controllers need to inherit from NomirunApiController to work with Nomirun Host and Swagger docuemntation generation.

We currently do not support minimal API

The Controller will be registered automatically when module is run by the Nomirun host. Endpoint and Swagger are automatically exposed on the HttpPort or HttpsPort (read more here).