Crews.Extensions.Http 3.0.0

Prefix Reserved
dotnet add package Crews.Extensions.Http --version 3.0.0
                    
NuGet\Install-Package Crews.Extensions.Http -Version 3.0.0
                    
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="Crews.Extensions.Http" Version="3.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Crews.Extensions.Http" Version="3.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Crews.Extensions.Http" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Crews.Extensions.Http --version 3.0.0
                    
#r "nuget: Crews.Extensions.Http, 3.0.0"
                    
#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.
#:package Crews.Extensions.Http@3.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Crews.Extensions.Http&version=3.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Crews.Extensions.Http&version=3.0.0
                    
Install as a Cake Tool

Crews.Extensions.Http

Provides extension methods and other utilities for working with HTTP resources.

Installation

dotnet add package Crews.Extensions.Http

Usage

HttpClient Extensions

SafelySetBaseAddress()

Safely sets the HttpClient.BaseAddress property while avoiding common URI permutation issues.

Now you never have to think about leading or trailing slashes again:

var client = new HttpClient();
var baseUri = new Uri("https://api.example.com/v1");

client.SafelySetBaseAddress(baseUri);

var response = await client.GetAsync("users"); 
// Gets https://api.example.com/v1/users

Uri Extensions

SetQueryString()

Set the query string of a Uri instance.

var uri = new Uri("https://example.com/api/data");
var queryString = new QueryString("?page=1&size=10&tags=important,urgent");

var newUri = uri.SetQueryString(queryString);
// Result: https://example.com/api/data?page=1&size=10&tags=important,urgent

This uses my robust custom QueryString structure to avoid the pitfalls of the built-in UriBuilder. But, there's a trade-off: you are responsible for escaping strings. This is because it's impossible for the library to know whether your string is already escaped.

ClearQueryString()

Remove the query string from a Uri:

var uri = new Uri("https://example.com/api/data?page=1&size=10");
var cleanUri = uri.ClearQueryString();
// Result: https://example.com/api/data
SafelyAppendPath()

Append paths to Uris without worrying about leading/trailing slashes:

var baseUri = new Uri("https://api.example.com/v1/");
var pathUri = baseUri.SafelyAppendPath("users/123");
// Result: https://api.example.com/v1/users/123

// Works regardless of slash configuration
var baseUri2 = new Uri("https://api.example.com/v1");
var pathUri2 = baseUri2.SafelyAppendPath("/users/123");
// Result: https://api.example.com/v1/users/123
EnsureTrailingSlash()

Ensure a Uri has one (and only one) trailing slash:

var uri1 = new Uri("https://example.com/api").EnsureTrailingSlash();
// Result: https://example.com/api/

var uri2 = new Uri("https://example.com/api///").EnsureTrailingSlash();
// Result: https://example.com/api/

Query String Utilities

This package also contains utility types for efficiently and safely working with query strings. You can even use custom delimiters.

QueryString

Parse and work with query strings:

// Parse a query string
var queryString = new QueryString("?name=John&tags=work,personal&active=true");

// Access parameters
foreach (var param in queryString.Parameters)
{
    Console.WriteLine($"{param.Key}: [{string.Join(", ", param.Values)}]");
}
// Output:
// name: [John]
// tags: [work, personal]
// active: [true]

// Convert back to string
string result = queryString.ToString();
// Result: ?name=John&tags=work,personal&active=true
QueryStringBuilder

Build query strings programmatically:

var builder = new QueryStringBuilder();

// Add parameters
builder.Parameters.Add(new QueryString.Parameter 
{ 
    Key = "search", 
    Values = ["user query"] 
});

builder.Parameters.Add(new QueryString.Parameter 
{ 
    Key = "filters", 
    Values = ["active", "verified", "premium"] 
});

// Build the query string
QueryString queryString = builder.QueryString;
string result = queryString.ToString();
// Result: ?search=user query&filters=active,verified,premium
Custom Delimiters

Customize delimiters for different query string formats:

var customQuery = new QueryString("name=John;tags=work:personal;active=true")
{
    BeginningDelimiter = "",
    ParameterDelimiter = ";",
    ParameterValuesDelimiter = ":"
};

// Parse with custom delimiters
foreach (var param in customQuery.Parameters)
{
    Console.WriteLine($"{param.Key}: [{string.Join(", ", param.Values)}]");
}
// Output:
// name: [John]
// tags: [work, personal]
// active: [true]

License

This project is licensed under the GPL-3.0-or-later license.

S.D.G.

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.  net9.0 was computed.  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.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  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 Crews.Extensions.Http:

Package Downloads
Crews.PlanningCenter.Api

A library containing basic models and services for interacting with the Planning Center API.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.0.0 166 9/22/2025
2.0.0 206 8/26/2025
1.0.0 251 11/29/2024