Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Htmx Headers #13

Open
Nairda015 opened this issue Mar 5, 2024 · 1 comment
Open

Htmx Headers #13

Nairda015 opened this issue Mar 5, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@Nairda015
Copy link
Contributor

Maybe we can add support for htmx headers by sending object instead of string

public class HtmxHeaders  //This will be added to library with fluent api or sth
{
    [JsonPropertyName("HX-Target")]
    public string Target { get; set; }
    [JsonPropertyName("HX-Push-Url")]
    public string PushUrl { get; set; }
}
var headers = new HtmxHeaders
{
  Target = "game",
  PushUrl = $"game/{log.GameId.ToString()}"
};

await hubContext.Clients
    .Group(log.GameId.Value)
    .SendAsync("game-started", message, new { HEADERS = headers }, ct);

this code will send

{
  "type": 1,
  "target": "game-started",
  "arguments": [
    "<div>Something</div>",
    {
      "headers": {
        "HX-Target": "game",
        "HX-Push-Url": "game/c-BsMYCRPQ"
      }
    }
  ]
}

Question is if this will break something and if this will be hard to handle in js?

For comparison this is message sent from the client to server

{
  "arguments": [
    {
      "playerId": "Walter.Bednar",
      "HEADERS": {
        "HX-Request": "true",
        "HX-Trigger": null,
        "HX-Trigger-Name": null,
        "HX-Target": "game",
        "HX-Current-URL": "http://192.168.0.10:5104/"
      }
    }
  ],
  "target": "newGame",
  "type": 1
}
@Renerick
Copy link
Owner

Renerick commented Mar 5, 2024

I thought about implementing it, but htmx doesn't expose a convenient method to handle all response headers automatically, so it would require copying and pasting headers processing from htmx core. I discarded this idea at the time, but thinking about it, maybe it's not that bad actually

The real issue is lack of history related methods in public or internal API, which are unlikely to be exposed in htmx 1.0, but I'll bring it up with the team

@Renerick Renerick added the enhancement New feature or request label Mar 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants