Nagornev.Querer.Http
1.1.1
dotnet add package Nagornev.Querer.Http --version 1.1.1
NuGet\Install-Package Nagornev.Querer.Http -Version 1.1.1
<PackageReference Include="Nagornev.Querer.Http" Version="1.1.1" />
<PackageVersion Include="Nagornev.Querer.Http" Version="1.1.1" />
<PackageReference Include="Nagornev.Querer.Http" />
paket add Nagornev.Querer.Http --version 1.1.1
#r "nuget: Nagornev.Querer.Http, 1.1.1"
#:package Nagornev.Querer.Http@1.1.1
#addin nuget:?package=Nagornev.Querer.Http&version=1.1.1
#tool nuget:?package=Nagornev.Querer.Http&version=1.1.1
Nagornev.Querer.Http
Information
This library was created to simplify working with the HTTP protocol by creating and handling requests in isolation.
Installation
Install the current version with dotnet:
dotnet add package Nagornev.Querer.Http
Usage
Quick start
Use this code to send an HTTP GET-request to the server httpbin. You will receive data about your request in JSON format.
QuererHttpClient client = new QuererHttpClient();
QuererHttpRequestMessageCompiler compiler = QuererHttpRequestMessageCompilerBuilder
.Create()
.UseMethod(c => c.Set(HttpMethod.Post))
.UseUrl(c => c.Set("http://httpbin.org/post"))
.UseHeaders(c => c.Set(new Dictionary<string, string>()
{
{ "Quick-Start-Header-Key", "QuickStartHeaderValue"}
}))
.UseContent(c => c.Set(new Dictionary<string, string>()
{
{ "quickStartContentKey", "QuickStartContentValue"}
}))
.UseScheme(s => s.Default())
.Build();
QuererHttpResponseMessageHandler<string> handler = QuererHttpResponseMessageHandlerBuilder<string>
.Create()
.UseConfigure(h => h.SetFailure(options => options.AddFailure<Exception>((response, excepion) => "Failure content"))
.SetLogger(options=> options.AddConsole()))
.UsePreview(h => h.Set(response => response.StatusCode == HttpStatusCode.OK))
.UseContent(h => h.Set(response => response.GetText())
.Confirm(content => !string.IsNullOrEmpty(content)))
.UseScheme(s => s.Default())
.Build();
await client.SendAsync(compiler, handler);
Console.WriteLine(handler.Content);
How to use it?
The main advantages of using Nagornev.Querer.Http is the creation requests and handing responses in isolation.
Request:
You can create a class for the request implementing QuererHttpRequestMessageCompiler:
public class Request : QuererHttpRequestMessageCompiler
{
protected override void SetMethod(MethodCompiler compiler)
{
compiler.Set(HttpMethod.Get);
}
protected override void SetUrl(UrlCompiler compiler)
{
compiler.Set(new Uri("https://httpbin.org/get"));
}
protected override void SetContent(ContentCompiler compiler)
{
compiler.Set(new Dictionary<string, string>()
{
{ "ContentKey", "ContentValue" }
});
}
protected override void SetHeaders(HeadersCompiler compiler)
{
compiler.Set(new Dictionary<string, string>()
{
{ "HeaderKey", "HeaderValue" }
});
}
protected override void SetRequest(RequestCompiler compiler)
{
compiler.Set(request =>
{
//Do something with HttpRequestMessage
});
}
protected override IEnumerable<Scheme.Set> SetScheme(Scheme scheme)
{
return scheme.Configure(scheme.Method, scheme.Url, scheme.Content, scheme.Headers, scheme.Request);
}
}
To configure the request, you can override the following methods:
SetMethod(compiler)- sets request method;SetUrl(compiler)- sets request url;SetContent(compiler)- sets request content;SetHeaders(compiler)- sets request headers;SetRequest(compiler)- sets any parameters HttpRequestMessage;SetScheme(schme)- sets compilation order;
Response:
You can create a class for the response implementing QuererHttpResponseMessageHandler<T>:
public class Response : QuererHttpResponseMessageHandler<string>
{
protected override void Configure(InvokerOptionsBuilder options)
{
options.SetFailure(options =>
{
options.AddFailure<Exception>((response, exception) =>
{
return "Failure content.";
});
})
.SetLogger(options => options.AddConsole());
}
protected override void SetPreview(PreviewHandler handler)
{
handler.Set(response => response.StatusCode == HttpStatusCode.OK);
}
protected override void SetContent(ContentHandler handler)
{
handler.Set(response => response.GetText())
.Confirm(content => !string.IsNullOrEmpty(content));
}
protected override IEnumerable<Scheme.Set> SetScheme(Scheme scheme)
{
return scheme.Configure(scheme.Preview, scheme.Content);
}
}
To configure the response, you can override the following methods:
Configure(options)- sets handling options.SetFailure(IvokerOptionsBuilder)- sets the methods to handle unhandled exceptions.SetLogger(QuererLoggerBuilder)- sets the handling loggers.SetPreview(handler)- sets HttpResponseMessage confirmations. This handler is needed to make sure that the response from the server is correct;SetContent(handler)- sets propertyQuererHttpResponseMessageHandler<T>.Content;SetScheme(scheme)- sets compilation order;
Sending:
You can send request and handle response with method QuererHttpClient.SendAsync():
var compiler = new Request();
var handler = new Response();
var client = new QuererHttpClient();
await client.SendAsync(compiler, handler);
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- HtmlAgilityPack (>= 1.11.65)
- Nagornev.Querer (>= 1.0.1)
- Newtonsoft.Json (>= 13.0.3)
- protobuf-net (>= 3.2.30)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|