Tolitech.Results.Http 1.0.0-alpha05

This is a prerelease version of Tolitech.Results.Http.
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package Tolitech.Results.Http --version 1.0.0-alpha05                
NuGet\Install-Package Tolitech.Results.Http -Version 1.0.0-alpha05                
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="Tolitech.Results.Http" Version="1.0.0-alpha05" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Tolitech.Results.Http --version 1.0.0-alpha05                
#r "nuget: Tolitech.Results.Http, 1.0.0-alpha05"                
#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.
// Install Tolitech.Results.Http as a Cake Addin
#addin nuget:?package=Tolitech.Results.Http&version=1.0.0-alpha05&prerelease

// Install Tolitech.Results.Http as a Cake Tool
#tool nuget:?package=Tolitech.Results.Http&version=1.0.0-alpha05&prerelease                

Results.Http

Overview

The Results.Http library provides extension methods for handling HTTP responses and populating a Result object. It contains a method ReadProblemDetailsAsync that reads the content of an HttpResponseMessage asynchronously and populates the provided Result object with the details extracted from the response.

Usage

To use the ReadProblemDetailsAsync method, follow these steps:

  1. Ensure you have a valid Result object to populate with response details.
  2. Obtain an HttpResponseMessage containing the response from an HTTP request.
  3. Call the ReadProblemDetailsAsync extension method on the Result object, passing the HttpResponseMessage as a parameter.
using Tolitech.Results.Http;

namespace Store.Ordering.Orders;

public sealed class OrderService : IOrderService
{
    private readonly HttpClient httpClient;

    public OrderService(OrderingHttpClient orderingHttpClient)
    {
        httpClient = orderingHttpClient.HttpClient;
    }

    public async Task<Result<CreateOrderResponse>> CreateOrder(CreateOrderRequest request, CancellationToken cancellationToken)
    {
        Result<CreateOrderResponse> result = new();

        string url = $"/orders";
        using var requestMessage = new HttpRequestMessage(HttpMethod.Post, url);
        requestMessage.Content = new StringContent(JsonSerializer.Serialize(request), Encoding.UTF8, "application/json");

        var response = await httpClient.SendAsync(requestMessage, cancellationToken);
        
        if (response.IsSuccessStatusCode)
        {
            var resp = await response.Content.ReadFromJsonAsync<CreateOrderResponse>();
            return result.OK(resp!);
        }

        await result.ReadProblemDetailsAsync(response);

        return result;
    }
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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. 
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
1.0.0-alpha07 57 7/28/2024
1.0.0-alpha06 56 7/7/2024
1.0.0-alpha05 50 7/7/2024
1.0.0-alpha04 73 3/13/2024
1.0.0-alpha03 57 3/5/2024
1.0.0-alpha02 58 3/4/2024
1.0.0-alpha01 56 3/4/2024