Nagornev.Querer.Http 1.1.1

The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package Nagornev.Querer.Http --version 1.1.1
                    
NuGet\Install-Package Nagornev.Querer.Http -Version 1.1.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Nagornev.Querer.Http" Version="1.1.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Nagornev.Querer.Http" Version="1.1.1" />
                    
Directory.Packages.props
<PackageReference Include="Nagornev.Querer.Http" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Nagornev.Querer.Http --version 1.1.1
                    
#r "nuget: Nagornev.Querer.Http, 1.1.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Nagornev.Querer.Http@1.1.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Nagornev.Querer.Http&version=1.1.1
                    
Install as a Cake Addin
#tool nuget:?package=Nagornev.Querer.Http&version=1.1.1
                    
Install as a Cake Tool

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 property QuererHttpResponseMessageHandler<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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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