CardboardBox.Http.Files 2.0.1

dotnet add package CardboardBox.Http.Files --version 2.0.1                
NuGet\Install-Package CardboardBox.Http.Files -Version 2.0.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="CardboardBox.Http.Files" Version="2.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add CardboardBox.Http.Files --version 2.0.1                
#r "nuget: CardboardBox.Http.Files, 2.0.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 CardboardBox.Http.Files as a Cake Addin
#addin nuget:?package=CardboardBox.Http.Files&version=2.0.1

// Install CardboardBox.Http.Files as a Cake Tool
#tool nuget:?package=CardboardBox.Http.Files&version=2.0.1                

CardboardBox.Http

Extension to HttpClientFactory that exposes common Http Request methods

Breaking Chnages in 2.0.0

There were some base changes in 2.0 that might break anyone using 1.x versions:

Fail Gracefully

In version 1.x, by default FailGracefully was enabled on all requests. This would make it so if the request failed with a status code outside of the 200 range, it would just return null. This has been turned off by default in 2.0.0. If you want to turn it back on, you can chain the .FailGracefully() builder on any IHttpBuilder or override the Create() method on the IApiService.

Fail With Throw

There is now a FailWithThrow option on the IHttpBuilder that allows for toggling the FailGracefully option, this previously didn't exist and was an oversight on my part.

Dependencies

The auto-inclusion of the CardboardBox.Json services in the dependency injection handler has been removed. You will need to manually add the CardboardBox.Json package to your dependency injection handler otherwise you will receive an error trying to resolve the IApiService. See the section in the installation instructions for more information.

Installation

You can install the nuget package within Visual Studio. It targets .net standard 2.1.

PM> Install-Package CardboardBox.Http

Dependencies

This library depends on the IJsonService provided in CardboardBox.Json and will need to be provided in the dependency injection setup. By default the library will use the System.Text.Json library for serialization and deserialization. This can be changed by providing a custom implementation of IJsonService in the dependency injection setup. There is also a default implementation of IJsonService provided in CardboardBox.Json that uses Newtonsoft.Json for serialization and deserialization.

You will need to use one of the following to register the IJsonService in the dependency injection setup:

using CardboardBox.Json;
using Microsoft.Extensions.DependencyInjection;
...
//Uses System.Text.Json (You can pass in a custom JsonSerializerOptions instance)
services.AddJson(); 

//Uses Newtonsoft.Json
services.AddJson<NewtonsoftJsonService>(); 

//Alternatively you can provide your own implementation of IJsonService
services.AddJson<MyCustomJsonService>();

Setup

You can setup the Api Client using the following code:

Where ever you register your services with Dependency Injection, you can add:

using CardboardBox.Http;
using Microsoft.Extensions.DependencyInjection;
...
services.AddCardboardHttp();

This will register the IHttpClientFactory as well as all of the other dependencies necessary for handling CardboardBox.Http.

Usage

Once CardboardBox.Http is registered with your service collection you can inject the IApiService into any of your services and get access to all of the default methods

using CardboardBox.Http;

namespace ExampleHttp
{
  public class SomeService 
  {
	private readonly IApiService _api;

	public SomeService(IApiService api)
	{
	  _api = api;
	}

	public Task<SomeModel> GetSomething()
	{
	  return _api.Get<SomeModel>("https://example.org");
	}
  }
}
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos 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 CardboardBox.Http.Files:

Package Downloads
CardboardBox.Epub.Network

Allows for building Epub ebooks in csharp - This adds more functionality to CardboardBox.Epub

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.0.1 192 10/9/2023
2.0.0 367 7/13/2023
1.0.1 1,206 10/20/2022
1.0.0 404 10/14/2022