A CLAUDE.md is just a markdown file at the root of your repo. Copy the content below into your own project's CLAUDE.md to give your agent the same context.
npx versuz@latest install restsharp-restsharp --kind=claude-mdcurl -o CLAUDE.md https://raw.githubusercontent.com/restsharp/RestSharp/HEAD/CLAUDE.md# CLAUDE.md This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. ## 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 ## 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 `Authenticate(IRestClient, RestRequest)` method. 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/`. ## 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