|
1 | | -## MCP Servers Available |
2 | | -- mem0: Use this AI memory for storing and retrieving long-term context as well as short-term context |
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Build & Test Commands |
| 6 | + |
| 7 | +```bash |
| 8 | +# Build |
| 9 | +dotnet build RestSharp.slnx -c Debug |
| 10 | + |
| 11 | +# Run all tests |
| 12 | +dotnet test RestSharp.slnx -c Debug |
| 13 | + |
| 14 | +# Run tests for a specific TFM |
| 15 | +dotnet test RestSharp.slnx -f net9.0 |
| 16 | + |
| 17 | +# Run a single test by fully-qualified name |
| 18 | +dotnet test test/RestSharp.Tests/RestSharp.Tests.csproj --filter "FullyQualifiedName=RestSharp.Tests.ObjectParserTests.ShouldUseRequestProperty" -f net8.0 |
| 19 | + |
| 20 | +# Pack |
| 21 | +dotnet pack src/RestSharp/RestSharp.csproj -c Release -o nuget -p:IncludeSymbols=true -p:SymbolPackageFormat=snupkg |
| 22 | +``` |
| 23 | + |
| 24 | +**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` |
| 25 | + |
| 26 | +## Project Overview |
| 27 | + |
| 28 | +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. |
| 29 | + |
| 30 | +### Repository Layout |
| 31 | + |
| 32 | +- `src/RestSharp/` — Core library |
| 33 | +- `src/RestSharp.Serializers.NewtonsoftJson/` — Newtonsoft.Json serializer adapter |
| 34 | +- `src/RestSharp.Serializers.Xml/` — Custom XML serializer |
| 35 | +- `src/RestSharp.Serializers.CsvHelper/` — CsvHelper serializer adapter |
| 36 | +- `src/RestSharp.Extensions.DependencyInjection/` — DI integration |
| 37 | +- `gen/SourceGenerator/` — Custom incremental source generators |
| 38 | +- `test/RestSharp.Tests/` — Unit tests |
| 39 | +- `test/RestSharp.Tests.Integrated/` — Integration tests (WireMock-based) |
| 40 | +- `test/RestSharp.Tests.Serializers.*/` — Serializer-specific tests |
| 41 | + |
| 42 | +## Architecture |
| 43 | + |
| 44 | +### Core Classes |
| 45 | + |
| 46 | +- **RestClient** (`RestClient.cs`, split into partials `RestClient.*.cs`) — Main entry point. Wraps `HttpClient`, holds `ReadOnlyRestClientOptions`, `RestSerializers`, and `DefaultParameters`. Thread-safe when configured via `RestClientOptions`. |
| 47 | +- **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. |
| 48 | +- **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>`. |
| 49 | +- **RestClientOptions** (`Options/RestClientOptions.cs`) — Mutable configuration class. An immutable `ReadOnlyRestClientOptions` wrapper is generated by `[GenerateImmutable]`. |
| 50 | + |
| 51 | +### Request Pipeline |
| 52 | + |
| 53 | +`ExecuteAsync` → build request → interceptor chain (`BeforeRequest` → `BeforeHttpRequest` → send → `AfterHttpRequest` → `AfterRequest`) → deserialization → error handling. Interceptors are configured via `RestClientOptions.Interceptors`. |
| 54 | + |
| 55 | +### Parameter System (`Parameters/`) |
| 56 | + |
| 57 | +Abstract `Parameter` record base with concrete types: `HeaderParameter`, `QueryParameter`, `BodyParameter`, `UrlSegmentParameter`, `FileParameter`, `GetOrPostParameter`, `CookieParameter`. `ObjectParser` converts objects to parameters via reflection. |
| 58 | + |
| 59 | +### Serialization (`Serializers/`) |
| 60 | + |
| 61 | +`ISerializer`/`IDeserializer` interfaces. `RestSerializers` manages serializers by `DataFormat` enum (Json, Xml, Csv). Default: `SystemTextJsonSerializer`. Configured via `ConfigureSerialization` delegate in client constructors. |
| 62 | + |
| 63 | +### Authentication (`Authenticators/`) |
| 64 | + |
| 65 | +`IAuthenticator` with single `Authenticate(IRestClient, RestRequest)` method. Built-in: `HttpBasicAuthenticator`, `JwtAuthenticator`, OAuth1/OAuth2 authenticators. Set via `RestClientOptions.Authenticator`. |
| 66 | + |
| 67 | +### Source Generators (`gen/SourceGenerator/`) |
| 68 | + |
| 69 | +- `[GenerateImmutable]` — Creates read-only wrapper (used on `RestClientOptions`) |
| 70 | +- `[GenerateClone]` — Creates static factory clone methods (used on `RestResponse<T>`) |
| 71 | +- `[Exclude]` — Excludes properties from immutable generation |
| 72 | +- Generator target must be `netstandard2.0`. Inspect output in `obj/<Config>/<TFM>/generated/SourceGenerator/`. |
| 73 | + |
| 74 | +## Multi-Targeting |
| 75 | + |
| 76 | +**Library:** `netstandard2.0`, `net471`, `net48`, `net8.0`, `net9.0`, `net10.0` |
| 77 | +**Tests:** `net48` (Windows only), `net8.0`, `net9.0`, `net10.0` |
| 78 | + |
| 79 | +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+. |
| 80 | + |
| 81 | +## Code Style & Conventions |
| 82 | + |
| 83 | +- **C# version:** preview (latest features) |
| 84 | +- **Nullable:** Enabled in `/src`, disabled in `/test` |
| 85 | +- **License header required** in all `/src` files (Apache-2.0, see `.github/copilot-instructions.md` for exact text) |
| 86 | +- **Strong-named** assemblies via `RestSharp.snk` |
| 87 | +- **Partial classes** for large types, linked via `<DependentUpon>` in csproj |
| 88 | +- **Package versions** centrally managed in `Directory.Packages.props` — don't pin in individual projects |
| 89 | +- **Versioning** via MinVer from git tags (no hardcoded versions) |
| 90 | +- Follow `.editorconfig` for formatting |
| 91 | + |
| 92 | +## Testing |
| 93 | + |
| 94 | +- **Stack:** xUnit + FluentAssertions + AutoFixture |
| 95 | +- **HTTP mocking:** WireMock.Net (avoid live endpoints) |
| 96 | +- Global usings in test projects: `Xunit`, `FluentAssertions`, `AutoFixture` |
| 97 | +- Guard TFM-specific tests with `#if NET8_0_OR_GREATER` |
| 98 | +- Test results: `test-results/<TFM>/<ProjectName>.trx` |
| 99 | + |
| 100 | +## Working with Issues |
| 101 | + |
| 102 | +- Avoid changing default behavior unless absolutely necessary |
| 103 | +- Avoid breaking the existing API |
| 104 | +- Leave existing tests intact to catch regressions; add new tests for fixed cases |
0 commit comments