Skip to content

Conversation

@alekcz
Copy link
Contributor

@alekcz alekcz commented Nov 4, 2025

SUMMARY

Creates a new datahike.http.router namespace that enables embedding Datahike's HTTP server as a library component with a connection registry for hybrid access patterns.

Key Changes:

  • New datahike.http.router namespace with route generation and Ring handler creation
  • Connection registry enabling local processes to directly access router-managed connections
  • Support for Transit+JSON and JSON serialization formats
  • Authentication and dev-mode configuration
  • Writer route generation for transactional operations
  • Three registry API functions: router/get-connection, router/list-connections, router/clear-connections!

Router Features:

  • Programmatic route creation without server startup
  • Embedded server capability via Ring handlers
  • Flexible serialization (Transit, JSON, EDN, raw)
  • Token-based authentication with dev-mode bypass
  • Route prefixing for reverse proxy scenarios

Connection Registry:

  • Store identity-based connection keys (robust, canonical)
  • Dual API: config map or store identity vector lookup
  • Automatic registration on HTTP connect, cleanup on release
  • Perfect consistency across HTTP and direct access methods

Checks

Feature
  • Implements an existing feature request. Make sure the feature request has been accepted for implementation before opening a PR.
  • Related issues linked using fixes #number
  • Integration tests added
  • Documentation added
  • Architecture Decision Record added
  • Formatting checked

ADDITIONAL INFORMATION

Test Coverage:

  • Router: 42 tests, 858 assertions, 0 failures
  • Comprehensive sync test verifies 4 connection types maintain perfect consistency
  • All connection types tested: HTTP CLIENT, MAIN (registry), WRITER, REMOTE-PEER

Example Usage:

;; Create embedded router
(require '[datahike.http.router :as router])
(def handler (router/create-ring-handler :config {:dev-mode true}))
(def server (jetty/run-jetty handler {:port 3000 :join? false}))

;; HTTP client connects (automatically registers connection)
(def conn (client/connect {:store {:backend :file :path "/data/db"}
                           :remote-peer {:backend :datahike-server 
                                        :url "http://localhost:3000"}}))

;; Local process retrieves same connection from registry
(def local-conn (router/get-connection {:store {:backend :file :path "/data/db"}}))

;; Local transactions bypass HTTP, visible to all clients
(d/transact local-conn [{:user/name "Alice"}])

@alekcz
Copy link
Contributor Author

alekcz commented Nov 7, 2025

@whilo could you have a look? I think it's ready.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant