Init
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
<div class="greeting">
|
||||
<h1>Hello, $$User$$!</h1>
|
||||
<p>Welcome to high-performance htmx rendering.</p>
|
||||
</div>
|
||||
@@ -0,0 +1,37 @@
|
||||
using Htmx.ApiDemo;
|
||||
using Immediate.Apis;
|
||||
using Immediate.Apis.Shared;
|
||||
using Immediate.Handlers.Shared;
|
||||
|
||||
namespace Htmx.ApiDemo.Templates;
|
||||
|
||||
public class Greeting : GreetingBase
|
||||
{
|
||||
private byte[] _userData = [];
|
||||
public required string Username { init => _userData = value.ToUtf8Bytes(); }
|
||||
protected override void RenderUser(HtmxRenderContext context) => context.Writer.WriteUtf8(_userData);
|
||||
}
|
||||
|
||||
[Handler]
|
||||
[MapGet("/greet/{username}")]
|
||||
public static partial class GetGreetingHandler
|
||||
{
|
||||
public record Query(string Username);
|
||||
|
||||
private static ValueTask HandleAsync(
|
||||
Query query,
|
||||
IHttpContextAccessor httpContextAccessor,
|
||||
CancellationToken token)
|
||||
{
|
||||
var context = httpContextAccessor.HttpContext;
|
||||
if(context is null)
|
||||
throw new InvalidOperationException("HttpContext is not available.");
|
||||
|
||||
var template = new Greeting { Username = query.Username };
|
||||
|
||||
context.Response.ContentType = "text/html; charset=utf-8";
|
||||
context.Response.BodyWriter.WriteHtmx(template);
|
||||
|
||||
return ValueTask.CompletedTask;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user