Skip to content
.NET C# API client for Consul (http://www.consul.io/)
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src Setup nuget package information Apr 25, 2018
tests/Consul.Net.Manual.Test
.gitignore
Consul.NET.sln Added IConsulClient<T> and DotNetHttpClient implementation Apr 25, 2018
LICENSE Initial commit Apr 24, 2018
MyGet.bat Added myget build scripts Apr 25, 2018
README.md Update README.md Apr 25, 2018
post-MyGet.ps1 Added myget build scripts Apr 25, 2018

README.md

Consul.NET

.NET C# API client for Consul (http://www.consul.io/)

  • Consul API: v1.0.7
  • .NET: >= 4.5 - .NETStandard >= 1.4

Consul.NET is an implementation of the Consul API for .NET. It is built on top of TypeSafe.Http.Net which is a typesafe automatic HTTP/REST client library based on Refit/Retrofit. This means that the Consul API implementation in this library provides a rich set of service interfaces with strongly typed JSON models where possible. Supports task-based async service calls and multiple HttpClient implementations are possible meaning if you or your company has their own HttpClient that must be used it can be implemented simply with TypeSafe.Http.Net.

Features

TODO

Getting Started

  1. Reference NuGet Consul.Net.API for projects that need to reference IConsul<T> or that require the Consul service interfaces as dependencies.

  2. Reference NuGet for client implementation. (Ex. Consul.Net.Client.DotNetHttpClient)

  3. Create a IConsul<T> client where T is the service interface you're interested in. (Ex IConsul<IConsulCatalogServiceHttpApiService>) see examples

  4. Make service calls with the client or register the Service field from IConsul<\T> with your IoC/DI container.

Examples

These examples assumes you're already running Consul and are already familiar with it. See the official Consul guide on getting started if you're not.

These examples will also assume you're using the Consul.Net.Client.DotNetHttpClient package.

You can reuse the created client. You do not need to create one per service call. Though the examples will show this behavior so that they are runnable.

Querying Consul Catalog API for Registered Services

The below example will query the Consul Catalog API for nodes that provide the service specified.

//Create the DotNetHttpClient Consul client for the Consul Catalog service interface
IConsulClient<IConsulCatalogServiceHttpApiService> consulCatalogService =
				new ConsulDotNetHttpClient<IConsulCatalogServiceHttpApiService>(@"http://localhost:8500");
        
CatalogServiceNodeEntry[] entries = await consulCatalogService.Service.GetServiceNodes("TestService");

Under Development

You can’t perform that action at this time.