Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/beetlex-io/httpclients
BeetleX http/websocket client support ssl
https://github.com/beetlex-io/httpclients
beetlex-http httpclients https-client tls websocket websocket-clients
Last synced: 18 days ago
JSON representation
BeetleX http/websocket client support ssl
- Host: GitHub
- URL: https://github.com/beetlex-io/httpclients
- Owner: beetlex-io
- License: apache-2.0
- Created: 2019-06-30T13:15:27.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2022-12-08T05:46:18.000Z (almost 2 years ago)
- Last Synced: 2024-10-13T22:36:06.715Z (about 1 month ago)
- Topics: beetlex-http, httpclients, https-client, tls, websocket, websocket-clients
- Language: C#
- Homepage:
- Size: 156 KB
- Stars: 35
- Watchers: 0
- Forks: 11
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# HttpClients
BeetleX http and websocket clients for .net standard2.0
## Install
```
Install-Package BeetleX.Http.Clients -Version 1.6
```
``` csharp
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()["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
``` csharp
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
``` csharp
public interface INorthWind
{
Task GetEmployee(int id);
[Post]
Task Add(Employee emp);
[Post]
Task Login(string name, string value);
[Post]
Task Modify([CQuery]int id, Employee body);
}
```
``` csharp
HttpCluster httpClusterApi = new HttpClusterApi();
httpCluster.DefaultNode.Add("http://localhost:8080");
northWind = httpCluster.Create();
var result = await northWind.GetEmployee(1);
```
### Multi server
``` csharp
httpCluster.DefaultNode
.Add("http://192.168.2.25:8080")
.Add("http://192.168.2.26:8080");
```
### Server weight
``` csharp
.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
``` csharp
[FormUrlFormater]
[Host("https://github.com")]
public interface IGithubAuth
{[Get(Route = "login/oauth/access_token")]
Task GetToken(string client_id, string client_secret, string code);[Host("https://api.github.com")]
[CHeader("User-Agent", "beetlex.io")]
[Get(Route = "user")]
Task GetUser(string access_token);
}
githubAuth = HttpApiClient.Create();
```### 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");
```