Tolitech.Results.Http 1.0.0-alpha04

This is a prerelease version of Tolitech.Results.Http.
dotnet add package Tolitech.Results.Http --version 1.0.0-alpha04
NuGet\Install-Package Tolitech.Results.Http -Version 1.0.0-alpha04
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-alpha04" />
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-alpha04
#r "nuget: Tolitech.Results.Http, 1.0.0-alpha04"
#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-alpha04&prerelease

// Install Tolitech.Results.Http as a Cake Tool
#tool nuget:?package=Tolitech.Results.Http&version=1.0.0-alpha04&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-alpha04 56 3/13/2024
1.0.0-alpha03 50 3/5/2024
1.0.0-alpha02 53 3/4/2024
1.0.0-alpha01 49 3/4/2024