This folder contains minimal, runnable console applications demonstrating common FluentHttpClient usage patterns. Each sample is self-contained and can be run with dotnet run.
cd sample/BasicGetSample
dotnet runDemonstrates the simplest possible GET request using FluentHttpClient.
What it shows:
- Creating an
HttpClientwith a base address - Using
UsingRoute()to specify an endpoint - Performing a GET request with
GetAsync() - Reading the response as a string
Run:
cd sample/BasicGetSample && dotnet runShows how to POST JSON content to an API.
What it shows:
- Creating JSON content from an anonymous object
- Using
WithJsonContent()to attach JSON to the request - Sending a POST request with
PostAsync() - Reading the response body
Run:
cd sample/JsonPostSample && dotnet runDemonstrates adding query string parameters to a request.
What it shows:
- Using
WithQueryParameter()to add query parameters - Automatic URL encoding and query string construction
- Retrieving filtered results from an API
Run:
cd sample/WithQueryParametersSample && dotnet runShows strongly-typed JSON deserialization using FluentHttpClient's built-in extensions.
What it shows:
- Defining a model class for deserialization
- Using
ReadJsonAsync<T>()to deserialize JSON responses - Accessing typed properties from the response
Run:
cd sample/JsonDeserializeSample && dotnet runDemonstrates XML deserialization from an HTTP response.
What it shows:
- Using
ReadXmlAsync<T>()to deserialize XML responses - Working with XML serialization attributes
- Handling complex XML structures with nested elements
Run:
cd sample/XmlDeserializeSample && dotnet runShows how to add custom headers to requests.
What it shows:
- Using
WithHeader()to add custom headers - Adding multiple headers to a single request
- Common patterns like correlation IDs
Run:
cd sample/WithHeadersSample && dotnet runDemonstrates adding authentication headers, specifically Bearer tokens.
What it shows:
- Using
WithOAuthBearerToken()for Bearer authentication - Adding Authorization headers to requests
- Common OAuth/API authentication patterns
Run:
cd sample/AuthenticationSample && dotnet runShows how to handle success and failure responses using FluentHttpClient's response handlers.
What it shows:
- Using
OnSuccess()to handle successful responses - Using
OnFailure()to handle failed responses - Fluent error handling without breaking the chain
Run:
cd sample/ErrorHandlingSample && dotnet runAll samples (except XML) use JSONPlaceholder, a free fake REST API for testing and prototyping. No authentication or setup is required.
- .NET 8.0 SDK or later
- All samples reference the local
FluentHttpClientproject