Coder Social home page Coder Social logo

httpclients's Introduction

HttpClients

BeetleX http and websocket clients for .net standard2.0

Install

Install-Package BeetleX.Http.Clients -Version 1.6
            var result = await "https://www.baidu.com/"
                    .FormUrlRequest()
                    .Get();
            Console.WriteLine(result.Body);

            result = await "https://httpbin.org/get"
                     .FormUrlRequest()
                     .Get();
            Console.WriteLine(result.Body);


            result = await "https://httpbin.org/post"
                     .JsonRequest()
                     .SetBody(DateTime.Now)
                     .Post();
            JToken rdata = result.GetResult<JToken>()["data"];

            Console.WriteLine(rdata);


            var buffer = await "https://httpbin.org/image"
                           .BinaryRequest()
                           .Download();

             result = await "http://localhost/Upload"
                           .FormDataRequest()
                           .Upload("g:\\extension_1_4_3_0.rar", "g:\\extension_1_4_3_0_1.rar");

Http Cluster

HttpCluster httpCluster = new HttpCluster();
httpCluster.DefaultNode
.Add("http://192.168.2.25:8080")
.Add("http://192.168.2.26:8080");
var client = httpCluster.JsonRequest("/customers?count=10");
var data = await client.Get();
client = httpCluster.JsonRequest("/orders?size=10");
data = await client.Get();

Http Cluster 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);
    }
HttpCluster httpClusterApi = new HttpClusterApi();
httpCluster.DefaultNode.Add("http://localhost:8080");
northWind = httpCluster.Create<INorthWind>();
var result = await northWind.GetEmployee(1);

Multi server

httpCluster.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");

httpclients's People

Contributors

beetlex-io avatar

Stargazers

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

httpclients'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.