https://github.com/catcherwong/nacos-csharp-extensions
Some extensions for nacos-sdk-csharp
https://github.com/catcherwong/nacos-csharp-extensions
nacos refit webapiclient
Last synced: 12 months ago
JSON representation
Some extensions for nacos-sdk-csharp
- Host: GitHub
- URL: https://github.com/catcherwong/nacos-csharp-extensions
- Owner: catcherwong
- License: apache-2.0
- Created: 2021-11-06T06:09:16.000Z (over 4 years ago)
- Default Branch: dev
- Last Pushed: 2022-01-22T05:50:13.000Z (over 4 years ago)
- Last Synced: 2025-06-22T13:02:43.326Z (about 1 year ago)
- Topics: nacos, refit, webapiclient
- Language: C#
- Homepage:
- Size: 72.3 KB
- Stars: 20
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# nacos-csharp-extensions [中文](./README.zh-cn.md)
Some extensions for `nacos-sdk-csharp`.
## Features
- Declarative REST Client Integration
1. WebApiClient Integration
2. WebApiClientCore Integration
3. Refit Integration
- Reverse proxy [YARP](https://github.com/microsoft/reverse-proxy) Integration
- Others..
## Basic Usage
### API Definition
```cs
// for webapiclient/core
[HttpHost("http://githubsvc")]
public interface IGitHubAPI : IHttpApi
{
[HttpGet("")]
Task Get();
}
// for refit
[Headers("User-Agent: Refit Nacos Tests")]
public interface IGitHubAPI
{
[Get("")]
Task Get();
}
```
> NOTE: The service name must be lowercase!
### Config
```cs
// nacos dependency
services.AddNacosV2Naming(x =>
{
});
// for webapiclient/core
services.AddNacosDiscoveryTypedClient("DEFAULT_GROUP", "DEFAULT");
// for refit
services.AddNacosDiscoveryTypedClient("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
```cs
[ApiController]
[Route("[controller]")]
public class ValuesController : ControllerBase
{
private readonly IGitHubAPI _api;
public ValuesController(IGitHubAPI api)
{
this._api = api;
}
[HttpGet]
public async Task Get()
{
var res = await _api.Get().ConfigureAwait(false);
return $"{res} from IGitHubAPI";
}
}
```