• Home
  • Integrations
  • SDKs
  • Guides
  • API docs
    No results for ""
    EXPAND ALL

    EDIT ON GITHUB

    Using proxy mode

    Read time: 3 minutes
    Last edited: Oct 31, 2022

    Overview

    Each SDK connects to several LaunchDarkly web services. These include services for getting feature flag data via streaming or polling, and a service for storing analytics events. By default, the SDK connects directly to LaunchDarkly for these services.

    If you are using the Relay Proxy, you must configure the SDK so that it connects to the Relay Proxy for these services instead.

    If you use the Relay Proxy in proxy mode, you must know the base uniform resource identifier (URI) of your Relay Proxy instance. This is an http or https address with the hostname and port where you have deployed the Relay Proxy. In all of the code examples below, the Relay Proxy's base URI is https://your-relay-proxy.com:8030, which is its default port.

    Different SDKs have different ways of configuring the SDK. In some SDKs, you must set the base URI of each service to the Relay Proxy's base URI, using a separate configuration property for each service but setting each one to the same value. In other SDKs, you can set the base URI for all services with a single configuration property.

    The examples below show how to configure the SDK for each service. In most SDKs, you then need to pass the configuration in as a parameter when you initialize the client. To learn more, read Configuration.

    The following examples also include configuring the events service. To learn more, read Deciding how to handle analytics events.

    Details about each SDK's configuration are available in the SDK-specific sections below:

    • Client-side SDKs
    • Server-side SDKs

    Client-side SDKs

    This feature is available in the following client-side SDKs:

    .NET (client-side)

    Expand .NET (client-side) code sample

    To connect the SDK to the Relay Proxy, use the ServiceEndpoints builder method and Components.ServiceEndpoints().RelayProxy to specify the base URI of your Relay Proxy:

    var config = Configuration.Builder("YOUR_MOBILE_KEY")
    .ServiceEndpoints(Components.ServiceEndpoints()
    .RelayProxy("https://your-relay-proxy.com:8030"))
    .Build();

    Android

    Expand Android code sample

    To connect the SDK to the Relay Proxy, use the streamUri, pollUri, and eventsUri builder methods to specify the base URI of your Relay Proxy:

    LDConfig ldConfig = new LDConfig.Builder()
    .mobileKey("YOUR_MOBILE_KEY")
    .streamUri(Uri.parse("https://your-relay-proxy.com:8030"))
    .pollUri(Uri.parse("https://your-relay-proxy.com:8030"))
    .eventsUri(Uri.parse("https://your-relay-proxy.com:8030"))
    .build();

    Electron

    Expand Electron code sample

    To connect the SDK to the Relay Proxy, set the streamUrl, baseUrl, and eventsUrl options to the base URI of your Relay Proxy:

    const options = {
    streamUrl: 'https://your-relay-proxy.com:8030',
    baseUrl: 'https://your-relay-proxy.com:8030',
    eventsUrl: 'https://your-relay-proxy.com:8030'
    };

    Flutter

    Expand Flutter code sample

    To connect the SDK to the Relay Proxy, use the streamUri, pollUri, and eventsUri builder methods to specify the base URI of your Relay Proxy:

    LDConfig ldConfig = LDConfigBuilder("YOUR_MOBILE_KEY")
    .streamUri("https://your-relay-proxy.com:8030")
    .pollUri("https://your-relay-proxy.com:8030")
    .eventsUri("https://your-relay-proxy.com:8030")
    .build();

    iOS

    Expand iOS code sample

    To connect the SDK to the Relay Proxy, set the streamUrl, baseUrl, and eventsUrl properties to the base URI of your Relay Proxy:

    var ldConfig = LDConfig(mobileKey: "YOUR_MOBILE_KEY")
    ldConfig.streamUrl = URL(string: "https://your-relay-proxy.com:8030")
    ldConfig.baseUrl = URL(string: "https://your-relay-proxy.com:8030")
    ldConfig.eventsUrl = URL(string: "https://your-relay-proxy.com:8030")

    JavaScript

    Expand JavaScript code sample

    To connect the SDK to the Relay Proxy, set the streamUrl, baseUrl, and eventsUrl properties to the base URI of your Relay Proxy:

    const options = {
    streamUrl: 'https://your-relay-proxy.com:8030',
    baseUrl: 'https://your-relay-proxy.com:8030',
    eventsUrl: 'https://your-relay-proxy.com:8030'
    };

    Node.js (client-side)

    Expand Node.js (client-side) code sample

    To connect the SDK to the Relay Proxy, set the streamUrl, baseUrl, and eventsUrl properties to the base URI of your Relay Proxy:

    const options = {
    streamUrl: 'https://your-relay-proxy.com:8030',
    baseUrl: 'https://your-relay-proxy.com:8030',
    eventsUrl: 'https://your-relay-proxy.com:8030'
    };

    React Native

    Expand React Native code sample

    To connect the SDK to the Relay Proxy, set the streamUri, pollUri, and eventsUri properties to the base URI of your Relay Proxy:

    let config = {
    mobileKey: 'YOUR_MOBILE_KEY',
    streamUri: 'https://your-relay-proxy.com:8030',
    pollUri: 'https://your-relay-proxy.com:8030',
    eventsUri: 'https://your-relay-proxy.com:8030',
    };

    Roku

    Expand Roku code sample

    To connect the SDK to the Relay Proxy, use the setStreamURI, setAppURI, and setEventsURI methods to specify the base URI of your Relay Proxy:

    REM for a legacy Roku application
    config = LaunchDarklyConfig("YOUR_MOBILE_KEY")
    REM for a SceneGraph Roku Application
    config = LaunchDarklyConfig("YOUR_MOBILE_KEY", CLIENT_SCENEGRAPH_NODE)
    config.setStreamURI("https://your-relay-proxy.com:8030")
    config.setAppURI("https://your-relay-proxy.com:8030")
    config.setEventsURI("https://your-relay-proxy.com:8030")

    Server-side SDKs

    This feature is available for the following server-side SDKs:

    .NET (server-side)

    Expand .NET (server-side) code sample

    To connect the SDK to the Relay Proxy, use the ServiceEndpoints builder method and Components.ServiceEndpoints().RelayProxy to specify the base URI of your Relay Proxy:

    var config = Configuration.Builder("YOUR_SDK_KEY")
    .ServiceEndpoints(Components.ServiceEndpoints()
    .RelayProxy("https://your-relay-proxy.com:8030"))
    .Build();

    C/C++ (server-side)

    Expand C/C++ (server-side) code sample

    To connect the SDK to the Relay Proxy, use LDConfigSetStreamURI, LDConfigSetBaseURI, and LDConfigSetEventsURI to specify the base URI of your Relay Proxy:

    struct LDConfig *config = LDConfigNew("YOUR_SDK_KEY");
    LDConfigSetStreamURI(config, "https://your-relay-proxy.com:8030");
    LDConfigSetBaseURI(config, "https://your-relay-proxy.com:8030");
    LDConfigSetEventsURI(config, "https://your-relay-proxy.com:8030");

    Erlang

    Expand Erlang code sample

    To connect the SDK to the Relay Proxy, set the stream_uri, base_uri, and events_uri properties to the base URI of your Relay Proxy:

    ldclient:start_instance("YOUR_SDK_KEY", #{
      stream_uri => "https://your-relay-proxy.com:8030",
      base_uri => "https://your-relay-proxy.com:8030",
      events_uri => "https://your-relay-proxy.com:8030"
    })
    
    

    Go

    Expand Go code sample

    To connect the SDK to the Relay Proxy, use the Config.ServiceEndpoints property and ldcomponents.RelayProxyEndpoints() to specify the base URI of your Relay Proxy:

    // To use the Replay Proxy in proxy mode for both streaming and events:
    config := ld.Config{
    ServiceEndpoints: ldcomponents.RelayProxyEndpoints(
    "https://your-relay-proxy.com:8030"),
    }
    // Alternatively, to use the Relay Proxy in proxy mode for streaming,
    // but send events directly to LaunchDarkly, use:
    config := ld.Config{
    ServiceEndpoints: ldcomponents.RelayProxyEndpointsWithoutEvents(
    "https://your-relay-proxy.com:8030"),
    }

    Haskell

    Expand Haskell code sample

    To connect the SDK to the Relay Proxy, use configSetStreamURI, configSetBaseURI, and configSetEventsURI to specify the base URI of your Relay Proxy:

    {-# LANGUAGE OverloadedStrings #-}
    import LaunchDarkly.Server.Config
    import Data.Function ((&))
    config :: Config
    config = (makeConfig "YOUR_SDK_KEY")
    & configSetStreamURI "https://your-relay-proxy.com:8030"
    & configSetBaseURI "https://your-relay-proxy.com:8030"
    & configSetEventsURI "https://your-relay-proxy.com:8030"

    Java

    Expand Java code sample

    To connect the SDK to the Relay Proxy, use the serviceEndpoints builder method and Components.serviceEndpoints().relayProxy to specify the base URI of your Relay Proxy:

    LDConfig config = new LDConfig.Builder()
    .serviceEndpoints(Components.serviceEndpoints()
    .relayProxy("https://your-relay-proxy.com:8030"))
    .build();

    Lua

    Expand Lua code sample

    To connect the SDK to the Relay Proxy, set the streamURI, baseURI, and eventsURI properties to the base URI of your Relay Proxy:

    local config = {
    key = YOUR_SDK_KEY,
    streamURI = "https://your-relay-proxy.com:8030",
    baseUri = "https://your-relay-proxy.com:8030",
    eventsURI = "https://your-relay-proxy.com:8030",
    }

    Node.js (server-side)

    Expand Node.js (server-side) code sample

    To connect the SDK to the Relay Proxy, set the streamUri, baseUri, and eventsUri properties to the base URI of your Relay Proxy:

    const options = {
    streamUri: 'https://your-relay-proxy.com:8030',
    baseUri: 'https://your-relay-proxy.com:8030',
    eventsUri: 'https://your-relay-proxy.com:8030',
    };

    PHP

    Expand PHP code sample

    To connect the SDK to the Relay Proxy, set the base_uri and events_uri properties to the base URI of your Relay Proxy:

    $client = new LaunchDarkly\LDClient("YOUR_SDK_KEY",
    [ "base_uri" => "https://your-relay-proxy.com:8030",
    "events_uri" => "https://your-relay-proxy.com:8030" ]);

    There is not a streaming service for the PHP SDK.

    Python

    Expand Python code sample

    To connect the SDK to the Relay Proxy, set the stream_uri, base_uri, and events_uri properties to the base URI of your Relay Proxy:

    config = Config(sdk_key='YOUR_SDK_KEY',
    stream_uri="https://your-relay-proxy.com:8030",
    base_uri="https://your-relay-proxy.com:8030",
    events_uri="https://your-relay-proxy.com:8030")

    Ruby

    Expand Ruby code sample

    To connect the SDK to the Relay Proxy, set the service endpoints to the base URI of your Relay Proxy:

    config = LaunchDarkly::Config.new(
    stream_uri: "https://your-relay-proxy.com:8030",
    base_uri: "https://your-relay-proxy.com:8030",
    events_uri: "https://your-relay-proxy.com:8030")