Skip to content

Clients and settings

Run the complete page example.

After defining your API interface, you need to connect it to the service your app will use. These pages show how to create that client, apply request settings and make the client available to the rest of your app. Generated clients are the normal path. The creation and request-builder pages explain when runtime reflection is needed and how it affects trimming and Native AOT. They also explain who should dispose the HTTP client.

PageWhat you can do
Create a clientCreate a generated client over a shared or new HttpClient, select an interface through Type, or use the reflection path when needed.
SettingsSet naming, serialization, request options and failure handling.
Dependency injectionRegister generated clients, named transports and keyed clients.
Request buildersSelect reflected methods by name and parameter types, or supply a request builder to client creation.

The client example project uses .NET 10, generated JSON metadata and local replies. Clients.RunAsync exercises generated clients. The separate reflection project exercises APIs that need runtime metadata and runtime compilation.

From the Refit checkout's src folder, run the reflection executable with:

dotnet run --project examples/Documentation/Clients/Reflection/Reflection.csproj -c Release

Use the AOT guide to publish generated examples as native code. Reflection examples use just-in-time compilation and do not demonstrate Native AOT compatibility.