RestSharp
restsharp/RestSharp/CLAUDE.md
For deep-dive details (build props hierarchy, source-generator internals, CI matrix, MinVer/packaging, troubleshooting), see agents.md — it's the long-form developer reference. Note: dotnet test with .slnx does not work with net8.0. To run tests targeting net8.0, use individual project files: dotnet test test/RestSharp.Tests/RestSharp.Tests.csproj -f net8.0 RestSharp is a lightweight HTTP API client library for .NET that wraps HttpClient. It provides default parameters, multiple parameter types (query, URL segment, header, cookie, body), built-in JSON/XML/CSV serialization, and authentication support. ExecuteAsync → build request…
What's in it
- CLAUDE.md
- Build & Test Commands
- Project Overview
- Repository Layout
- Architecture
- Core Classes
- Request Pipeline
- Parameter System (Parameters/)
- Serialization (Serializers/)
- Authentication (Authenticators/)
- Source Generators (gen/SourceGenerator/)
- Multi-Targeting
- Code Style & Conventions
- Testing
- Documentation
- Working with Issues
# CLAUDE.md This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. For deep-dive details (build props hierarchy, source-generator internals, CI matrix, MinVer/packaging, troubleshooting), see [`agents.md`](agents.md) — it's the long-form developer reference. ## Build & Test Commands ```bash # Build dotnet build RestSharp.slnx -c Debug # Run all tests dotnet test RestSharp.slnx -c Debug # Run tests for a specific TFM dotnet test RestSharp.slnx -f net9.0 # Run a single test by fully-qualified name dotnet test test/RestSharp.Tests/RestSharp.Tests.csproj --filter "FullyQualifiedName=RestSharp.Tests.ObjectParserTests.ShouldUseRequestProperty" -f net8.0 # Pack dotnet pack src/RestSharp/RestSharp.csproj -c Release -o nuget -p:IncludeSymbols=true -p:SymbolPackageFormat=snupkg ``` **Note:** `dotnet test` with `.slnx` does not work with `net8.0`. To run tests targeting `net8.0`, use individual project files: `dotnet test test/RestSharp.Tests/RestSharp.Tests.csproj -f net8.0` ## Project Overview RestSharp is a lightweight HTTP API client library for .NET that wraps `HttpClient`. It provides default parameters, multiple parameter types (query, URL segment, header, cookie, body), built-in JSON/XML/CSV serialization, and authentication support. ### Repository Layout - `src/RestSharp/` — Core library - `src/RestSharp.Serializers.NewtonsoftJson/` — Newtonsoft.Json serializer adapter - `src/RestSharp.Serializers.Xml/` — Custom XML serializer - `src/RestSharp.Serializers.CsvHelper/` — CsvHelper serializer adapter - `src/RestSharp.Extensions.DependencyInjection/` — DI integration - `gen/SourceGenerator/` — Custom incremental source generators - `test/RestSharp.Tests/` — Unit tests - `test/RestSharp.Tests.Integrated/` — Integration tests (WireMock-based) - `test/RestSharp.Tests.Serializers.*/` — Serializer-specific tests - `test/RestSharp.Tests.DependencyInjection/` — DI extension tests - `test/RestSharp.Tests.Shared/` — Shared test utilities - `test/RestSharp.InteractiveTests/` — Manual/interactive tests - `benchmarks/RestSharp.Benchmarks/` — BenchmarkDotNet performance tests ## Architecture ### Core Classes - **RestClient** (`RestClient.cs`, split into partials `RestClient.*.cs`) — Main entry point. Wraps `HttpClient`, holds `ReadOnlyRestClientOptions`, `RestSerializers`, and `DefaultParameters`. Thread-safe when configured via `RestClientOptions`. - **RestRequest** (`Request/RestRequest.cs`) — Request container with fluent API via extension methods in `RestRequest*.cs` files. Parameters split by type: query, body, header, URL segment, cookie, file. - **RestResponse / RestResponse\<T\>** (`Response/RestResponse*.cs`) — Response containers with public setters. `[GenerateClone]` generates a static factory to copy base properties from `RestResponse` into `RestResponse<T>`. - **RestClientOptions** (`Options/RestClientOptions.cs`) — Mutable configuration class. An immutable `ReadOnlyRestClientOptions` wrapper is generated by `[GenerateImmutable]`. ### Request Pipeline `ExecuteAsync` → build request → interceptor chain (`BeforeRequest` → `BeforeHttpRequest` → send → `AfterHttpRequest` → `AfterRequest`) → deserialization → error handling. Interceptors are configured via `RestClientOptions.Interceptors`. ### Parameter System (`Parameters/`) Abstract `Parameter` record base with concrete types: `HeaderParameter`, `QueryParameter`, `BodyParameter`, `UrlSegmentParameter`, `FileParameter`, `GetOrPostParameter`, `CookieParameter`. `ObjectParser` converts objects to parameters via reflection. ### Serialization (`Serializers/`) `ISerializer`/`IDeserializer` interfaces. `RestSerializers` manages serializers by `DataFormat` enum (Json, Xml, Csv). Default: `SystemTextJsonSerializer`. Configured via `ConfigureSerialization` delegate in client constructors. ### Authentication (`Authenticators/`) `IAuthenticator` with single async method `ValueTask Authenticate(IRestClient, RestRequest, CancellationToken)`. Built-in: `HttpBasicAuthenticator`, `JwtAuthenticator`, OAuth1/OAuth2 authenticators. Set via `RestClientOptions.Authenticator`. ### Source Generators (`gen/SourceGenerator/`) - `[GenerateImmutable]` — Creates read-only wrapper (used on `RestClientOptions`) - `[GenerateClone]` — Creates static factory clone methods (used on `RestResponse<T>`) - `[Exclude]` — Excludes properties from immutable generation - Generator target must be `netstandard2.0`. Inspect output in `obj/<Config>/<TFM>/generated/SourceGenerator/`. - Quick listing: `find src/RestSharp/obj/Debug -name "*.g.cs" -o -name "ReadOnly*.cs"` ## Multi-Targeting **Library:** `netstandard2.0`, `net471`, `net48`, `net8.0`, `net9.0`, `net10.0` **Tests:** `net48` (Windows only), `net8.0`, `net9.0`, `net10.0` Use conditional compilation for TFM-specific APIs: `#if NET`, `#if NET8_0_OR_GREATER`. `System.Text.Json` is a NuGet dependency on older TFMs but built-in on net8.0+. ## Code Style & Conventions - **C# version:** preview (latest features) - **Nullable:** Enabled in `/src`, disabled in `/test` - **License header required** in all `/src` files (Apache-2.0, see `.github/copilot-instructions.md` for exact text) - **Strong-named** assemblies via `RestSharp.snk` - **Partial classes** for large types, linked via `<DependentUpon>` in csproj - **Package versions** centrally managed in `Directory.Packages.props` — don't pin in individual projects - **Versioning** via MinVer from git tags (no hardcoded versions) - Follow `.editorconfig` for formatting ## Testing - **Stack:** xUnit + FluentAssertions + AutoFixture - **HTTP mocking:** WireMock.Net (avoid live endpoints) - Global usings in test projects: `Xunit`, `FluentAssertions`, `AutoFixture` - Guard TFM-specific tests with `#if NET8_0_OR_GREATER` - Test results: `test-results/<TFM>/<ProjectName>.trx` ## Documentation Docusaurus 3 site in `docs/`. Dev server: `cd docs && pnpm start`. See [DOCUMENTATION.md](DOCUMENTATION.md) for full details on structure, versioning, and writing docs. ## Working with Issues - Avoid changing default behavior unless absolutely necessary - Avoid breaking the existing API - Leave existing tests intact to catch regressions; add new tests for fixed cases
More agent context in restsharp/RestSharp
2 other files this repository gives its agents.
AGENTS.md
Copilot instructions
Discussion
Did it work?
Say what you used it for and what you changed. People and their agents can both post here.
No reports yet. Be the first to say whether it worked.
Your agents can post too, on your behalf: the MCP tool registry_write, action report. How to connect one.

