https://htmx.org logo
Join Discord
Powered by
# htmx-general
  • l

    lively-vegetable-81321

    02/28/2023, 2:47 PM
    Hey folks! I'm new to htmx but trying to learn as we're considering using it in production at work. I see from [this](https://deploy-preview-51--hypermedia-systems.netlify.app/book/more-htmx-patterns/#_http_request_headers_in_htmx) that custom HTTP headers are used to figure out whether a full HTML page should be returned or just a snippet and I wonder why content negotiation using the Accept header isn't used for this purpose instead? It seems to be achieving essentially the same behavior but since custom headers are used it degrades interoperability. Is it possible to use the Accept header to get this behavior?
  • s

    some-airline-73512

    02/28/2023, 2:59 PM
    It's your backend, everything is possible. You decide what response to return
  • s

    some-airline-73512

    02/28/2023, 2:59 PM
    It's not a framework that tells you what to do. It's a library
  • l

    lively-vegetable-81321

    02/28/2023, 3:01 PM
    OK, so is there a way to get htmx to send a given Accept header in the GET request? Note that I haven't looked closely at the docs so it may be a naive question.
  • s

    some-airline-73512

    02/28/2023, 3:02 PM
    You can configure request headers like this https://htmx.org/events/#htmx:configRequest
  • s

    some-airline-73512

    02/28/2023, 3:04 PM
    There are also default headers for every htmx request https://htmx.org/docs/#request-headers
  • l

    lively-vegetable-81321

    02/28/2023, 3:07 PM
    Thanks @some-airline-73512 .
  • m

    mysterious-toddler-20573

    02/28/2023, 3:49 PM
    I have shied away from Accept headers because I am worried that some servers might barf if I introduced a new non-standard MIME type, but the idea has come up
  • t

    tall-dinner-62086

    02/28/2023, 3:52 PM
    What would we use as a value for the accept header? We want html, that's no different than any standard page load
  • l

    lively-vegetable-81321

    02/28/2023, 3:56 PM
    I would use a vendor-specific type, e.g., "application/vnd.mycompany.mytype+html", but that's me. I don't think "text/html" is the correct type for an HTML snippet in any case.
  • m

    mysterious-toddler-20573

    02/28/2023, 3:56 PM
    that's right, last I looked I didn't see an obvious existing MIME type and inventing one felt presumptive of me
  • m

    mysterious-toddler-20573

    02/28/2023, 3:56 PM
    but it's an idea worth looking at, for sure
  • r

    refined-waiter-90422

    02/28/2023, 3:57 PM
    will nginx play nice with something not already in here?
  • m

    mysterious-toddler-20573

    02/28/2023, 3:57 PM
    (I have to admit, the MIME-wars of early REST discussions put me off on the whole thing a bit as well)
  • g

    great-gold-37694

    02/28/2023, 4:01 PM
    I've always viewed Accept Headers to mean "file type" or extension. Like this endpoint can serve some resource as CSV, HTML, JSON, whatever but not like any more granular than any one of those. 🤔
  • g

    great-gold-37694

    02/28/2023, 4:05 PM
    My understanding of what @lively-vegetable-81321 is asking for our use case would be roughly analogous to the
    HX-Request
    header but instead of just a boolean it'd be per typeclass instance (haskell) ... So PeopleView.hs
    Copy code
    haskell
    -- This would be for the default HTML content type text/html
    instance ToMarkup Socials where
      toMarkup = socialH
    
    --socialH :: Maybe Text -> Bool -> [Social] -> Html
    socialH :: Socials -> Html
    socialH (Socials socials q locked) = do
    HtmlTable.hs
    Copy code
    haskell
    data HTMLTable
    
    instance Accept HTMLTable where
      contentType _ = "application" // "vnd.mycompany.people+html-table"
    
    -- instance ToMarkup a => MimeRender HTMLTable a where
    --     mimeRender _ = renderHtml . toHtml
    
    instance MimeRender HTMLTable Socials where
      mimeRender _ (Socials socials q _) = renderHtml $ socialTableH q socials
    
    socialTableH :: Maybe Text -> [Social] -> Html
    socialTableH q socials =
      socials &
      filter
  • g

    great-gold-37694

    02/28/2023, 4:05 PM
    So depending on the ContentType the Browser was asking for it could get the different responses instead of doing an
    if
    /
    else
    on the request header?
  • m

    mysterious-toddler-20573

    02/28/2023, 4:06 PM
    that's an open question, and it goes for app servers too, so I felt that not messing w/ it was the best option (maybe wrong!)
  • r

    refined-waiter-90422

    02/28/2023, 4:07 PM
    yup, totally understandable.
  • m

    mysterious-toddler-20573

    02/28/2023, 4:07 PM
    However! w/
    htmx:configRequest
    and friends, it can be experimented with by users
  • g

    great-gold-37694

    02/28/2023, 4:08 PM
    Okay then that's probably the answer. I'm the crazy person suggesting all this shenanigans but I think some of my peers like @lively-vegetable-81321 might be amenable to this Grug-based neo-web1.0 space 😅
  • g

    great-gold-37694

    02/28/2023, 4:08 PM
    🤞
  • r

    refined-waiter-90422

    02/28/2023, 4:11 PM
    also very true: starlette (fastapi), sanic, many of the golang frameworks... they can all serve themselves without a forward proxy (nginx/caddy/apache).
  • r

    refined-waiter-90422

    02/28/2023, 4:11 PM
    heck one of sanic's main selling points is you don't need anything in front, lol.
  • a

    adventurous-ocean-93733

    02/28/2023, 8:54 PM
    I recently registered a mime type to the IANA vendor tree and it was a doddle.
  • m

    mysterious-toddler-20573

    02/28/2023, 8:58 PM
    what does doddle mean
  • a

    adventurous-ocean-93733

    02/28/2023, 8:58 PM
    But my view is that since it’s exchanging html then the current mime-type makes sense. @lively-vegetable-81321 interested if you know of any companies using vendor specific mime types for html fragments
  • a

    adventurous-ocean-93733

    02/28/2023, 8:59 PM
    British English for “piece of piss”. Which is British English for “easy as pie”.
  • l

    lively-vegetable-81321

    02/28/2023, 9:02 PM
    @adventurous-ocean-93733 Actually no, but perhaps my company can be the first! Not a lot of companies (that I'm aware of) even use custom content types at all with the notable exception of Github as seen here: https://docs.github.com/en/rest/overview/media-types?apiVersion=2022-11-28
  • e

    enough-petabyte-50314

    03/01/2023, 12:33 AM
    using a custom MIME type would sort of restrict the clients that know how to interpret your resources though.
1...105310541055...1146Latest