decentrl.
SDK

Transport Layer

The pluggable transport system that handles HTTP and WebSocket communication with mediators.

The transport layer handles all communication between the client and mediators. By default, the SDK uses HTTP for commands and WebSocket for real-time push. You can provide a custom transport implementation for testing or alternative protocols.

Default Transport

The default transport provides:

  • HTTP — for all command/query operations (POST requests with signed envelopes)
  • WebSocket — for real-time event push (authenticated connection, server-sent events)

The client automatically resolves the mediator's service endpoint from the DID document and establishes connections as needed.

Custom Transport

You can replace the default transport with a custom implementation:

const app = defineDecentrlApp({
  mediator: 'did:web:mediator.decentrl.io',
  events: { ... },
  transport: {
    send: async (endpoint, command) => {
      // Custom send logic
      return response
    },
    subscribe: (endpoint, callback) => {
      // Custom real-time subscription
      return unsubscribe
    },
  },
})

This is useful for testing (mock transport), alternative protocols (gRPC, QUIC), or specialized environments (React Native, Electron).