This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
# 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=snupkgNote: 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.
src/RestSharp/— Core librarysrc/RestSharp.Serializers.NewtonsoftJson/— Newtonsoft.Json serializer adaptersrc/RestSharp.Serializers.Xml/— Custom XML serializersrc/RestSharp.Serializers.CsvHelper/— CsvHelper serializer adaptersrc/RestSharp.Extensions.DependencyInjection/— DI integrationgen/SourceGenerator/— Custom incremental source generatorstest/RestSharp.Tests/— Unit teststest/RestSharp.Tests.Integrated/— Integration tests (WireMock-based)test/RestSharp.Tests.Serializers.*/— Serializer-specific tests
- RestClient (
RestClient.cs, split into partialsRestClient.*.cs) — Main entry point. WrapsHttpClient, holdsReadOnlyRestClientOptions,RestSerializers, andDefaultParameters. Thread-safe when configured viaRestClientOptions. - RestRequest (
Request/RestRequest.cs) — Request container with fluent API via extension methods inRestRequest*.csfiles. 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 fromRestResponseintoRestResponse<T>. - RestClientOptions (
Options/RestClientOptions.cs) — Mutable configuration class. An immutableReadOnlyRestClientOptionswrapper is generated by[GenerateImmutable].
ExecuteAsync → build request → interceptor chain (BeforeRequest → BeforeHttpRequest → send → AfterHttpRequest → AfterRequest) → deserialization → error handling. Interceptors are configured via RestClientOptions.Interceptors.
Abstract Parameter record base with concrete types: HeaderParameter, QueryParameter, BodyParameter, UrlSegmentParameter, FileParameter, GetOrPostParameter, CookieParameter. ObjectParser converts objects to parameters via reflection.
ISerializer/IDeserializer interfaces. RestSerializers manages serializers by DataFormat enum (Json, Xml, Csv). Default: SystemTextJsonSerializer. Configured via ConfigureSerialization delegate in client constructors.
IAuthenticator with single Authenticate(IRestClient, RestRequest) method. Built-in: HttpBasicAuthenticator, JwtAuthenticator, OAuth1/OAuth2 authenticators. Set via RestClientOptions.Authenticator.
[GenerateImmutable]— Creates read-only wrapper (used onRestClientOptions)[GenerateClone]— Creates static factory clone methods (used onRestResponse<T>)[Exclude]— Excludes properties from immutable generation- Generator target must be
netstandard2.0. Inspect output inobj/<Config>/<TFM>/generated/SourceGenerator/.
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+.
- C# version: preview (latest features)
- Nullable: Enabled in
/src, disabled in/test - License header required in all
/srcfiles (Apache-2.0, see.github/copilot-instructions.mdfor 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
.editorconfigfor formatting
- 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
- 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