Tolitech.Results.Http
1.0.0-alpha06
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.
See the version list below for details.
dotnet add package Tolitech.Results.Http --version 1.0.0-alpha06
NuGet\Install-Package Tolitech.Results.Http -Version 1.0.0-alpha06
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-alpha06" />
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-alpha06
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Tolitech.Results.Http, 1.0.0-alpha06"
#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-alpha06&prerelease // Install Tolitech.Results.Http as a Cake Tool #tool nuget:?package=Tolitech.Results.Http&version=1.0.0-alpha06&prerelease
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
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 | 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.
-
net8.0
- Tolitech.Results (>= 1.0.0-alpha10)
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 | 62 | 7/28/2024 |
1.0.0-alpha06 | 61 | 7/7/2024 |
1.0.0-alpha05 | 55 | 7/7/2024 |
1.0.0-alpha04 | 78 | 3/13/2024 |
1.0.0-alpha03 | 66 | 3/5/2024 |
1.0.0-alpha02 | 65 | 3/4/2024 |
1.0.0-alpha01 | 61 | 3/4/2024 |