Tolitech.Results.Http 1.0.0-preview.1

This is a prerelease version of Tolitech.Results.Http.
dotnet add package Tolitech.Results.Http --version 1.0.0-preview.1                
NuGet\Install-Package Tolitech.Results.Http -Version 1.0.0-preview.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="Tolitech.Results.Http" Version="1.0.0-preview.1" />                
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-preview.1                
#r "nuget: Tolitech.Results.Http, 1.0.0-preview.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.
// Install Tolitech.Results.Http as a Cake Addin
#addin nuget:?package=Tolitech.Results.Http&version=1.0.0-preview.1&prerelease

// Install Tolitech.Results.Http as a Cake Tool
#tool nuget:?package=Tolitech.Results.Http&version=1.0.0-preview.1&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 net9.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Tolitech.Results.Http:

Package Downloads
Tolitech.HttpServices

Generic HTTP service implementation for .NET, based on Tolitech.HttpServices.Abstractions, with full support for JSON and custom headers.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0-preview.1 50 12/6/2024
1.0.0-alpha07 66 7/28/2024
1.0.0-alpha06 67 7/7/2024
1.0.0-alpha05 59 7/7/2024
1.0.0-alpha04 81 3/13/2024
1.0.0-alpha03 71 3/5/2024
1.0.0-alpha02 70 3/4/2024
1.0.0-alpha01 64 3/4/2024