Git Product home page Git Product logo

nacos-csharp-extensions's Introduction

nacos-csharp-extensions 中文

Some extensions for nacos-sdk-csharp.

Features

  • Declarative REST Client Integration
    1. WebApiClient Integration
    2. WebApiClientCore Integration
    3. Refit Integration
  • Reverse proxy YARP Integration
  • Others..

Basic Usage

API Definition

// for webapiclient/core
[HttpHost("http://githubsvc")]
public interface IGitHubAPI : IHttpApi
{
    [HttpGet("")]
    Task<string> Get();
}

// for refit
[Headers("User-Agent: Refit Nacos Tests")]
public interface IGitHubAPI
{
    [Get("")]
    Task<HttpResponseMessage> Get();
}

NOTE: The service name must be lowercase!

Config

// nacos dependency
services.AddNacosV2Naming(x =>
{
});

// for webapiclient/core
services.AddNacosDiscoveryTypedClient<IGitHubAPI>("DEFAULT_GROUP", "DEFAULT");

// for refit
services.AddNacosDiscoveryTypedClient<IGitHubAPI>("DEFAULT_GROUP", "DEFAULT")
        .ConfigureHttpClient(c =>
        {
            // The service name must be lowercase!
            c.BaseAddress = new Uri("http://githubsvc");
            c.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
        });

Call

[ApiController]
[Route("[controller]")]
public class ValuesController : ControllerBase
{
    private readonly IGitHubAPI _api;

    public ValuesController(IGitHubAPI api)
    {
        this._api = api;
    }

    [HttpGet]
    public async Task<string> Get()
    {
        var res = await _api.Get().ConfigureAwait(false);

        return $"{res} from IGitHubAPI";
    }
}

nacos-csharp-extensions's People

Contributors

catcherwong avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

nacos-csharp-extensions's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.