Generated Code¶
The HTTP Client generator produces a complete effects-native pipeline from your annotated partial classes — six artifacts from a single [HttpClient] declaration.
Interface¶
An interface I{TypeName} is generated for each client, enabling DI registration and test mocking:
// Generated
public interface IUsersClient
{
Task<User> GetUser(int id, CancellationToken token = default);
Task<User> CreateUser(CreateUserRequest request, CancellationToken token = default);
Task<List<User>> ListUsers(int page, int perPage, string requestId, CancellationToken token = default);
Task<Unit> DeleteUser(int id, CancellationToken token = default);
}
Capability Interface¶
A capability interface IHas{TypeName} is generated for effects composition:
This enables compile-time capability checking — your effects can only call HTTP methods when the runtime provides the capability. See Effects for details.
Effects Module¶
A static effects module {TypeName}Effects wraps each HTTP method in an Eff<RT, T>:
// Generated
public static partial class UsersClientEffects
{
public static partial class UsersClient
{
public static Eff<RT, User> GetUser<RT>(int id)
where RT : IHasUsersClient => ...
public static Eff<RT, User> CreateUser<RT>(CreateUserRequest request)
where RT : IHasUsersClient => ...
}
}
Each method includes activity tracing and error context. See Effects for the full pattern.
Test Client¶
A test client Test{TypeName} is generated with call recording and configurable responses:
// Generated
public class TestUsersClient : IUsersClient
{
// Call recording
public IReadOnlyList<int> GetUserCalls => _getUserCalls;
public IReadOnlyList<CreateUserRequest> CreateUserCalls => _createUserCalls;
// Configurable responses
public User GetUserResult { get; set; } = default!;
public User CreateUserResult { get; set; } = default!;
public Task<User> GetUser(int id, CancellationToken token = default)
{
_getUserCalls.Add(id);
return Task.FromResult(GetUserResult);
}
// ...
}
See Testing for usage patterns.
DI Registration¶
A generated extension method registers the client and its interface with the service collection:
This registers:
- The client implementation via
IHttpClientFactoryas theIUsersClientservice - The configured base address (if specified via
BaseAddressproperty) - A
TestUsersClientfallback viaTryAddSingleton(overridden by the real client above) - Authentication handlers (if any auth attributes are applied)
Configuration Binding¶
When using [HttpClient<TConfig>], the base address and other settings are resolved from the bound configuration type at runtime:
The BaseAddress property on the attribute serves as a compile-time default. At runtime, the configuration provider can override it — see Configuration for details.