Skip to main content

Blazor - Enable API Endpoints

21 Aug 2020 - Cody Merritt Anhorn

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; }

Categories: blog blazor

Tags: .NET Core C# Blazor

Cody Merritt Anhorn