Skip to content

BeetleX http https ws wss clients for .net standard2.0

License

Notifications You must be signed in to change notification settings

csharp2012/HttpClients

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

HttpClients

BeetleX http and websocket clients for .net standard2.0

WebApi

Defined interface

    public interface INorthWind
    {
        Task<Employee> GetEmployee(int id);
        [Post]
        Task<Employee> Add(Employee emp);
        [Post]
        Task<bool> Login(string name, string value);       
        [Post]
        Task<Employee> Modify([CQuery]int id, Employee body);
    }

Create interface

HttpClusterApi httpClusterApi = new HttpClusterApi();
httpClusterApi.DefaultNode.Add("http://localhost:8080");
northWind = httpClusterApi.Create<INorthWind>();
var result = await northWind.GetEmployee(1);

Multi server

httpClusterApi.DefaultNode
    .Add("http://192.168.2.25:8080")
    .Add("http://192.168.2.26:8080");

Server weight

.Add("http://192.168.2.25:8080",10)
.Add("http://192.168.2.26:8080",10);
.Add("http://192.168.2.27:8080",5);

Multi url route

httpClusterApi.GetUrlNode("/order.*")
    .Add("http://192.168.2.25:8080")
    .Add("http://192.168.2.26:8080");
httpClusterApi.GetUrlNode("/employee.*")
    .Add("http://192.168.2.27:8080")
    .Add("http://192.168.2.28:8080");

github auth sample

    [FormUrlFormater]
    [Host("https://github.com")]
    public interface IGithubAuth
    {

        [Get(Route = "login/oauth/access_token")]
        Task<string> GetToken(string client_id, string client_secret, string code);

        [Host("https://api.github.com")]
        [CHeader("User-Agent", "beetlex.io")]
        [Get(Route = "user")]
        Task<string> GetUser(string access_token);
    }
     githubAuth = HttpApiClient.Create<IGithubAuth>();

Websocket

Create wsclient

TextClient client = new TextClient("ws://echo.websocket.org");

send text

 await client.Send("hello");

send and receive

var resutl = await wss.ReceiveFrom("hello henry");

About

BeetleX http https ws wss clients for .net standard2.0

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%