Tolitech.Results.Http
1.0.0-preview.1
dotnet add package Tolitech.Results.Http --version 1.0.0-preview.1
NuGet\Install-Package Tolitech.Results.Http -Version 1.0.0-preview.1
<PackageReference Include="Tolitech.Results.Http" Version="1.0.0-preview.1" />
paket add Tolitech.Results.Http --version 1.0.0-preview.1
#r "nuget: Tolitech.Results.Http, 1.0.0-preview.1"
// 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:
- Ensure you have a valid
Result
object to populate with response details. - Obtain an
HttpResponseMessage
containing the response from an HTTP request. - Call the
ReadProblemDetailsAsync
extension method on theResult
object, passing theHttpResponseMessage
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 | Versions 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. |
-
net9.0
- Tolitech.Results (>= 1.0.0-preview.1)
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 |