NBoomackClient
Show / Hide Table of Contents

Client Configuration

The following aspects of the Boomack API Client need configuration:

  • URL of the Boomack Server
  • Authentication token
  • Timeout for requests
  • Response format (Text, JSON, HTML)
  • Mapping from filename patterns to media types

A client configuration is represented by the class ClientConfiguration.

A simple client configuration with default values for a local server is available as ClientConfiguration.Default. It uses the following settings:

  • Server URL: http://localhost:3000
  • Timeout: 20 seconds
  • Response Format: Text
  • Authentication Token: none
  • Media Type Mapping: Default Mapping

If you instantiate a BoomackClient without any configuration, this default configuration is used in the background.

// instantiating a BoomackClient with default configuration
using var client = new BoomackClient();

Basic Style

With the basic style you can specify the configuration explicitly. Parsing environment variables and configuration files is currently only supported in the fluent style.

var config = new ClientConfiguration()
{
    ServerUrl = new Uri("http://127.0.0.1:3000"),
    Token = "<Your Authentication Token>",
    RequestTimeout = TimeSpan.FromSeconds(20),
    ResponseFormat = ResponseFormat.JSON,
};
config.TypeMapping = DefaultMediaTypeMapping.LoadMapping();
config.TypeMapping["*.xyz"] = "application/x-y-z";

Fluent Style

When using the builder API for the client configuration, additional convenient methods are available.

var config = ClientConfiguration.Builder
    .For("http://127.0.0.1:3000")
    .WithToken("<Your Authentication Token>")
    .WithRequestTimeout(TimeSpan.FromSeconds(20))
    .WithResponseFormat(ResponseFormat.JSON)
    .WithTypeMapping("*.xyz", "application/x-y-z")
    .UseDefaultConfigFiles()
    .UseConfigFile("my-custom-config.yaml", required: true)
    .UseEnvironmentVariables()
    .BuildConfiguration();

The order of the method calls is important. Changes made by later calls override changes from earlier calls. Therefore, later calls have higher priority.

Default Configuration Files

The default configuration files are loaded from the following locations in that order:

  • .boomack-server[.json|.yaml|.yml] in the user profile
  • boomack-server[.json|.yaml|yml] in the current working directory
  • .boomack[.json|.yaml|.yml] in the user profile
  • boomack[.json|.yaml|.yml] in the current working directory

The config files in the current working directory and the user profile can have no filename extension or one of the following: .json, .yaml, .yml. And they are looked up in that order. Meaning, if a file boomack in the current working directory exists, another file with name boomack.yaml will be ignored.

Environment Variables

The following environment variables are supported:

  • BOOMACK_SERVER_HOST: The hostname or IP address of the server
  • BOOMACK_SERVER_PORT: The port of the server
  • BOOMACK_SERVER_URL: API base URL of the server
  • BOOMACK_CLIENT_TOKEN: API authentication token
  • BOOMACK_CLIENT_TIMEOUT: Timeout for the API requests in milliseconds
  • BOOMACK_CLIENT_FORMAT: The response format (text/plain, application/json, text/html)

The variable BOOMACK_SERVER_URL has priority over the variables BOOMACK_SERVER_HOST and BOOMACK_SERVER_PORT.

Media Type Mapping

The library comes with a set of default media type mappings. In the basic style these can be loaded as a dictionary with DefaultMediaTypeMapping.LoadMapping(). In the fluent style the default media type mappings are always loaded.


Next: Display Request

In This Article
Back to top
Boomack Homepage