Skip to content

Commit

Permalink
docs: add example of adding a WebProxy using DI (#1181)
Browse files Browse the repository at this point in the history
Adds example of configuring a WebProxy when using the DI project.
  • Loading branch information
mortenbock authored Jul 29, 2022
1 parent 8d1e10a commit 812d121
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,15 +185,6 @@ class Program
}
```

<a name="proxy"></a>
## Web Proxy

```csharp
var apiKey = Environment.GetEnvironmentVariable("SENDGRID_API_KEY");
var proxy = new WebProxy("http://proxy:1337");
var client = new SendGridClient(proxy, apiKey);
```

## HttpClientFactory + Microsoft.Extensions.DependencyInjection

> [SendGrid.Extensions.DependencyInjection](https://www.nuget.org/packages/SendGrid.Extensions.DependencyInjection) is required
Expand Down Expand Up @@ -234,6 +225,30 @@ class Program
}
```

<a name="proxy"></a>
## Web Proxy

```csharp
var apiKey = Environment.GetEnvironmentVariable("SENDGRID_API_KEY");
var proxy = new WebProxy("http://proxy:1337");
var client = new SendGridClient(proxy, apiKey);
```

Or when using DependencyInjection

```csharp
services.AddSendGrid(options =>
{
options.ApiKey = Environment.GetEnvironmentVariable("SENDGRID_API_KEY");
})
.ConfigurePrimaryHttpMessageHandler(_ => new HttpClientHandler()
{
Proxy = new WebProxy(new Uri("http://proxy:1337")),
UseProxy = true
});
```


# Usage

- [Twilio SendGrid Docs](https://docs.sendgrid.com/api-reference/)
Expand Down

0 comments on commit 812d121

Please sign in to comment.