Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ using HttpClientToCurl;
builder.Services.AddHttpClientToCurl(builder.Configuration);

// Enable curl logging for selected clients
builder.Services.AddHttpClient("my-client1", showCurl: true);
builder.Services.AddHttpClient("my-client1").AddCurlLogging();
```

**appsettings.json**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@ public async Task SendAndShowCurl()
await SendRemoteRequest("my-client1");
}

[HttpGet("send")]
public async Task Send()
{
await SendRemoteRequest("my-client2");
}

private async Task SendRemoteRequest(string httpClientName)
{
string apiUrl = "https://jsonplaceholder.typicode.com/posts";
Expand Down
3 changes: 1 addition & 2 deletions examples/HttpClientToCurl.Sample.InSpecific/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
builder.Services.AddControllers();

builder.Services.AddHttpClientToCurl(builder.Configuration);
builder.Services.AddHttpClient("my-client1", showCurl: true);
builder.Services.AddHttpClient("my-client2");
builder.Services.AddHttpClient("my-client1").AddCurlLogging();

var app = builder.Build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ public static void AddHttpClientToCurl(
AddServices(services, configuration);
}

[Obsolete($@"
{nameof(AddHttpClient)} extension method is deprecated and will be removed in future versions.
Instead, please use {nameof(AddCurlLogging)}, which is an extension built on top of the original AddHttpClient."
)]
public static IHttpClientBuilder AddHttpClient(this IServiceCollection services, string name, bool showCurl = false)
{
var httpClientBuilder = HttpClientFactoryServiceCollectionExtensions.AddHttpClient(services, name);
Expand All @@ -44,6 +48,9 @@ public static IHttpClientBuilder AddHttpClient(this IServiceCollection services,
return httpClientBuilder;
}

public static void AddCurlLogging(this IHttpClientBuilder httpClientBuilder)
=> httpClientBuilder.AddHttpMessageHandler<CurlGeneratorHttpMessageHandler>();

private static void AddServices(IServiceCollection services, IConfiguration configuration)
{
services.Configure<CompositConfig>(configuration.GetSection("HttpClientToCurl"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void ServiceCollectionExtensions_AddHttpMessageHandler_When_ShowCurl_IsEn
var services = new ServiceCollection();

services.AddTransient<CurlGeneratorHttpMessageHandler>();
services.AddHttpClient("TestClient", true);
services.AddHttpClient("TestClient").AddCurlLogging();

var serviceProvider = services.BuildServiceProvider();
var httpClientFactory = serviceProvider.GetRequiredService<IHttpClientFactory>();
Expand All @@ -85,7 +85,7 @@ public void ServiceCollectionExtensions_AddHttpMessageHandler_When_ShowCurl_IsNo
var services = new ServiceCollection();

services.AddTransient<CurlGeneratorHttpMessageHandler>();
services.AddHttpClient("TestClient", false);
services.AddHttpClient("TestClient");

var serviceProvider = services.BuildServiceProvider();
var httpClientFactory = serviceProvider.GetRequiredService<IHttpClientFactory>();
Expand Down
Loading