$ show restsharp/RestSharp
RestSharp is a mature .NET HTTP client library that wraps HttpClient into a fluent request/response API. It is not a standalone application; it ships as NuGet packages consumed by other projects. The core RestClient handles execution through an async pipeline: interceptors, authenticators, request content construction, cookie containers, redirect handling, and response deserialization. RestRequest models parameters (query, header, body, URL segments, cookies, files) and is built fluently through extension methods. Responses are RestResponse<T> with error aggregation and throw helpers, making failure handling explicit and consistent. The architecture is modular: a core library plus optional serializer packages for Newtonsoft.Json, System.Text.Json, XML, and CsvHelper, a DI integration package for Microsoft dependency injection, and a Roslyn source generator that produces immutable and clone variants of configuration types. Authentication is pluggable via IAuthenticator, with built-in Basic, JWT, OAuth1 signature generation, and OAuth2 client-credentials/refresh-token/token authenticators. Serialization is managed by a registry keyed by data format and content type, with automatic body sniffing between JSON and XML. The codebase multi-targets netstandard2.0, net471, net48, net8.0, net9.0, and net10.0, and includes extensive unit and WireMock-based integration tests, benchmarks, and versioned Docusaurus documentation. Code quality is strong: clean separation of concerns, extensive use of extension methods for ergonomics, custom source generation for option immutability, and a comprehensive test suite covering OAuth1 official vectors, redirect behavior, cookies, serializer edge cases, and interceptor ordering. Some legacy surface remains (obsolete hooks, polyfills for old TFMs), but the project tracks current .NET releases and is actively maintained. This is a well-crafted library that remains one of the standard HTTP client abstractions in the .NET ecosystem.
The LLM identified 5 files worth highlighting for reuse:
Uses compiled LINQ expression trees instead of raw reflection to build fast property getters for object-to-parameter conversion. Handles IFormattable, IConvertible, and collection types with CSV/array query dispatch. This is an extractable high-performance reflection mapping pattern useful for any object-to-dictionary/parameter transformation.
A sophisticated XML-to-object mapper supporting attribute and element mapping, case/underscore/dash name normalization, namespaces, nested and inline list deserialization, nullable values, and custom name overrides via DeserializeAsAttribute. Demonstrates a robust convention-over-configuration mapping engine that survives abstraction from the HTTP client.
Self-contained OAuth2 authenticator that acquires and refreshes access tokens using SemaphoreSlim to serialize concurrent token renewals, avoiding thundering herd problems. Uses its own internal HttpClient, decoupling it from the main client. This is a clean, reusable token lifecycle manager pattern for any OAuth2 client.
Central serializer registry that selects the appropriate IDeserializer/ISerializer by DataFormat and accepted content type, with automatic JSON/XML detection from the response body's first character. Demonstrates a pluggable strategy pattern that can be extracted into any HTTP content negotiation or multi-format serialization system.
An incremental Roslyn source generator that produces Clone.g.cs implementations for types marked with [GenerateClone] or [GenerateImmutable]. This removes hand-written boilerplate for copying immutable option objects and is a reusable template for generating derived-type factories or immutable variants in any C# codebase.