Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Full Stream Ahead: Breaking the protocol barrie...

Full Stream Ahead: Breaking the protocol barrier with http4k

HTTP's request-response pattern has served us well, but modern web applications demand more. Real-time communication demands different protocols, yet maintaining testability and simplicity remains crucial to developer experience.

In this talk, we'll explore how http4k extends HTTP's capabilities through WebSocket and Server-Sent Events support and how these protocols can be modelled as simple functions, making them as testable as plain HTTP endpoints. We'll then show how these streaming capabilities open up new possibilities for server-side rendering, bringing us full circle from the days of JSP to modern reactive interfaces - all while keeping the complexity on the server where it belongs.

Join us to discover how http4k's streaming capabilities can enhance your web applications, enabling everything from chat applications to live dashboards and reactive server-rendered interfaces.

Avatar for David Denton

David Denton

April 11, 2025
Tweet

More Decks by David Denton

Other Decks in Technology

Transcript

  1. What’s the plan? •The history of dynamic UIs •Di!erent types

    of web technology •How http4k models protocols as functions •Why the future could be simpler than you think
  2. CGI / Server Templates (mid 1990s) Browser Backend <html><li>user1!"li>!"html> Connection

    GET / <html><li>user1!"li><li>user2!"li>!"html> Connection GET / Manual Refresh
  3. JavaScript Power! (late 1990s) Browser Backend <html><li>user1!"li>!"html> Connection GET /

    <html><li>user1!"li><li>user2!"li>!"html> Connection GET / JS Refresh
  4. AJAX & SPA (Client Rendering) (2005+) Browser Backend GET /

    HTML + JS Bundle Connection GET /users [ { user1 } ] Connection XmlHttpRequest
  5. AJAX & SPA (Client Rendering) (2005+) Browser Backend GET /

    HTML + JS Bundle Connection GET /users [ { user1 } ] Connection XmlHttpRequest GET /users [ { user1 }, { user2 } ] Connection XmlHttpRequest
  6. Browser Backend 101 Switching Protocols Connection HTTP GET /ws [Connection:

    upgrade, Upgrade: Websocket] Websockets (2011) Frame [Text] [ { user1 } ] Connection Frame [Text] users (Push) Web Socket
  7. Browser Backend 101 Switching Protocols Connection HTTP GET /ws [Connection:

    upgrade, Upgrade: Websocket] Websockets (2011) Frame [Text] [ { user1 }, { user2 } ] (Push) Frame [Text] [ { user1 } ] Connection Frame [Text] users (Push) Web Socket
  8. Websockets: realtime pain Can’t use HTTP features (caching, compression) Don’t

    play nicely with Load Balancers, proxies Complexity, Observability, DevEx No reconnection
  9. Server Sent Events (2015) Browser Backend Event Source event: data

    data: [ { user1 } ] Connection GET /users, [accept=text/event-stream] Connection GET / <html><ul id=“users”!#!"html>
  10. Server Sent Events (2015) Browser Backend Event Source event: data

    data: [ { user1 } ] Connection GET /users, [accept=text/event-stream] event: data data: [ { user1 }, { user 2 } ] (Push) Connection GET / <html><ul id=“users”!#!"html>
  11. Browser Backend JS Bundle + <html!# Connection GET / SPA

    + Server Rendering (2016+) <ul><li>user1!"li>!"ul> Connection GET /users XmlHttpRequest
  12. Browser Backend JS Bundle + <html!# Connection GET / SPA

    + Server Rendering (2016+) <ul><li>user1!"li>!"ul> Connection GET /users XmlHttpRequest <ul><li>user1!"li><li>user2!"li>!"ul> Connection GET /users XmlHttpRequest
  13. SPA: a pain in the App UX performance, SEO APIs

    expose security attack service Heavyweight JS bundles Complexity, state management
  14. event: merge-fragments data: <ul id=“users”><li>user1!"li>!"ul> GET /users on-load SSE events

    are merged into the DOM GET /data event: merge-signals data: [{ user1 }] on-click
  15. Datastar pushes data to the Client Browser Backend <html><ul id=“users”

    data-on-load=“@get(‘/users’)”!"ul>!"html> Connection GET /
  16. Datastar pushes data to the Client Browser Backend <html><ul id=“users”

    data-on-load=“@get(‘/users’)”!"ul>!"html> Connection GET / Connection event: datastar-merge-fragments data: <ul id=“users”><li>user1!"li>!"ul> GET /users, accept=“text/event-stream“ XmlHttpRequest
  17. Datastar pushes data to the Client Browser Backend <html><ul id=“users”

    data-on-load=“@get(‘/users’)”!"ul>!"html> Connection GET / Connection event: datastar-merge-fragments data: <ul id=“users”><li>user1!"li>!"ul> GET /users, accept=“text/event-stream“ XmlHttpRequest event: datastar-merge-fragments data: <ul id=“users”><li>user1!"li><li>user2!"li>!"ul> (Push)
  18. Datastar pushes data to the Client Browser Backend <html><ul id=“users”

    data-on-load=“@get(‘/users’)”!"ul>!"html> Connection GET / Connection event: datastar-merge-fragments data: <ul id=“users”><li>user1!"li>!"ul> GET /users, accept=“text/event-stream“ XmlHttpRequest event: datastar-merge-fragments data: <ul id=“users”><li>user1!"li><li>user2!"li>!"ul> (Push) GET /data, accept=“text/event-stream“ event: datastar-merge-signals data: [ { user1 }, { user 2 } ] XmlHttpRequest Connection
  19. Datastar: a beacon of sanity in FE Full server-controlled reactivity

    Lightweight - ~12kb total (!) Simple to understand, operate, test State stays on backend
  20. What have we learned? •The internet has been around for

    a long time •Everything old is new again! •You can do quite a lot with 12kb of JS!
  21. • Feb 2025: v6 released • Now 180 modules •

    Technology Migration packs • Pro tier integrations an entire HTTP ecosystem Latest integrations
  22. Thank you! _____________? David Denton Architect | Head of Engineering

    | Advisory | Training https://clockwork.ing/ https://http4k.org