• Blazor
  • .NET Core
  • .NET
  • C#

Blazor - Enable API Endpoints

Just a quick post showing how to enable API controllers in a Blazor server application. I noticed, for performance, the default templates I used does not automatically wire up API controllers that are in your application. To enable API controllers you just need to add to the endpoints mapping, endpoints.MapControllers();.

Example Source Code

Startup.cs for project

public class Startup
    // ... Standard Startup Methods

    public void Configure(IApplicationBuilder app)
        // ... Standard Startup.Configure Method

        app.UseEndpoints(endpoints =>
            // Here is the mapping of Controllers, which includes our API Controller


using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc;

public class ValuesApiController : ControllerBase
    public IActionResult Values()
        return Ok(
            new ValuesResult
                Values = new List<string>
public class ValuesResult
    public IList<string> Values { get; set; }
Cody's logo image, it is an abstract of a black hole with a white Event Horizon.

Cody Merritt Anhorn

A Engineer with a passion for Platform Architecture and Tool Development.