Mapping Endpoints

How to Use Rizzy with Minimal APIs

First, let’s define a component that will display a message:

LoveHtmx.razor
<div class="alert alert-info">
	<span class="text-lg-center">
		@Message
	</span>
</div>

@code{
    [Parameter]
    public string? Message { get; set; } = "I ❤️ HTMX";
}

Configure the Endpoint

Configure an endpoint in your Minimal API setup that utilizes Rizzy to render the above partial view. This demonstrates how to use Rizzy’s PartialView method to serve dynamic content based on the Message parameter. If you want your View to be an entire page, utilize the View method.

app.MapGet("/love-htmx",
    ([FromServices] IRizzyService rizzy) => rizzy.PartialView<LoveHtmx>(new { Message = "I ❤️ ASP.NET Core" }));

Conclusion

After configuring the endpoint, run your application. When a client sends a request to /love-htmx, the server uses Rizzy to render the partial view with the message “I ❤️ ASP.NET Core”. This demonstrates a basic but powerful integration of Rizzy with Minimal APIs in .NET 8 for rendering dynamic views.