Csharp .NET Client for Remote Configuration
This is a library that simplifies using remote configurations with your csharp .NET projects. Joystick is a modern remote config platform to manage all of your configurable parameters. Change the behavior of your application without requiring code updates. We are natively multi-environment, preserve your version history, have advanced work-flow & permissions management, and much more. Have one API to use for any remote configs.
Provided client is supporting .NET Standard 2.1+, .NET Core 3.1+, .NET 5.0+, .NET 6.0+, .NET 7.0+.
Installation
Using the .NET Core command-line interface (CLI) tools:
Using the NuGet Command Line Interface (CLI):
Using the Package Manager Console:
From within Visual Studio:
- Open the Solution Explorer.
- Right-click on a project within your solution.
- Click on Manage NuGet Packages...
- Click on the Browse tab and search for "Joystick".
- Click on the Stripe.net package, select the appropriate version in the right-tab and click Install.
Usage
Using Joystick to get remote configurations in your .NET project is a breeze.
// Import the package.
using Joystick.Client;
// Initialize a client with a Joystick API Key
var config = new JoystickClientConfig()
{
ApiKey = "<put-your-api_key-here>",
};
var joystickClient = new JoystickClient(config);
// Request a single configuration as Newtonsoft JObject
const contentId1 = await joystickClient.GetContentAsync("content-id1");
// Request a typed single configuration
const contentId1Typed = await joystickClient.GetContentAsync<TypeForContentId1>(
"content-id1"
);
// Request multiple configurations at the same time
const configurations = await joystickClient.GetContentsAsync(new[]{
"content-id1",
"content-id2",
});
// {
// "content-id1": {...},
// "content-id2": {...}
// }
Specifying Additional Parameters
When creating the Joystick
object, you can specify additional parameters which will be used by all API calls to the Joystick API. These additional parameters are used for AB Testing (userId
), segmentation (params
), and backward-compatible version delivery (semVer
).
For more details see API documentation.
// Initializing a client with options
var config = new JoystickClientConfig()
{
ApiKey = "some-api-key",
SemVer = "0.0.1",
UserId = "user-id-1",
Params = new Dictionary<string, object>()
{
{ "Country", "PL" },
{ "UserPrc", 85.08 },
},
CacheOptions = new JoystickCacheOptions() {
CacheExpirationSeconds = 600, // default 600 (10 mins)
},
};
Error handling
The client can raise different types of exceptions with the base class of JoystickException
.
try {
const configurations = await joystickClient.GetContentsAsync(new[]{
"content-id1",
"content-id2",
});
}
catch (JoystickApiHttpException e) {
// Handle HTTP error (i.e. timeout, or invalid HTTP code)
}
catch (MultipleContentsApiException e) {
// Handle API exception (i.e. content is not found, or some of the keys can't be retrieved)
}
Caching
By default, the client uses JoystickDefaultCacheService, based on MemoryCache.
You can specify your own cache implementation by implementing the interface SdkCache.
Refresh
option
To ignore the existing cache when requesting a config, pass this option as true
.
var options = new JoystickContentOptions()
{
Refresh = true;
}
await joystickClient
.GetContentAsync("content-id1", options);
// OR
await joystickClient
.GetContentsAsync(new[] {"content-id1", "content-id2"}, options);
Clear the cache
If you want to clear the cache:
License
The MIT. Please see License File for more information.