Last modified: Nov 10, 2024

Exposing APIs from an app

More APIs can be added than what is defined as the default API for applications developed in Altinn Studio.

The applications that are developed in Altinn Studio are based on ASP.NET Core for back-end. This provides a highly flexible environment to change and modify the applications.

Adding an API controller

To expose a new API to an application, you have to add one or more API controllers.

Below is an example from an API controller which has been added to an app. This is where the API path listener is set up along with the API logic.

using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;

namespace Altinn.App.Api.Controllers
{
    [ApiController]
    [Route("{org}/{app}/CustomApi")]
    public class CustomApiController : ControllerBase
    {
        [HttpGet("TimeInfo")]
        public async Task<ActionResult> Get()
        {
            return Ok(DateTime.Now);
        }
    }
}

Test of API in web browser
API response

The code can be viewed in this repository.

You can read more details about the possibilities for exposing an API in the documentation for ASP.NET.