https://github.com/soenneker/soenneker.twilio.restclient
An async thread-safe singleton for a Twilio RestClient
https://github.com/soenneker/soenneker.twilio.restclient
async client csharp dotnet rest restclient singleton twilio twiliorestclientutil util
Last synced: 7 days ago
JSON representation
An async thread-safe singleton for a Twilio RestClient
- Host: GitHub
- URL: https://github.com/soenneker/soenneker.twilio.restclient
- Owner: soenneker
- License: mit
- Created: 2024-02-24T21:31:34.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2026-04-14T12:57:53.000Z (2 months ago)
- Last Synced: 2026-04-14T14:34:24.626Z (2 months ago)
- Topics: async, client, csharp, dotnet, rest, restclient, singleton, twilio, twiliorestclientutil, util
- Language: C#
- Homepage: https://soenneker.com
- Size: 2.86 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: .github/CODE_OF_CONDUCT.md
- Security: .github/SECURITY.md
Awesome Lists containing this project
README
[](https://www.nuget.org/packages/soenneker.twilio.restclient/)
[](https://github.com/soenneker/soenneker.twilio.restclient/actions/workflows/publish-package.yml)
[](https://www.nuget.org/packages/soenneker.twilio.restclient/)
[](https://github.com/soenneker/soenneker.twilio.restclient/actions/workflows/codeql.yml)
#  Soenneker.Twilio.RestClient
### An async thread-safe singleton for a Twilio RestClient
## Installation
```
dotnet add package Soenneker.Twilio.RestClient
```
## Why?
This library provides a singleton of a `TwilioRestClient`.
Internally it implements an `HttpClient` singleton. This `HttpClient` has less overhead than new instances of `HttpClient` and `IHttpClientFactory` all while correctly handling connection pooling for DNS changes.
See [soenneker.utils.httpclientcache](https://github.com/soenneker/soenneker.utils.httpclientcache) for more information.
## Usage
1. Register `ITwilioRestClientUtil` with DI.
```csharp
public static async Task Main(string[] args)
{
...
builder.Services.AddTwilioRestClientUtilAsSingleton();
}
```
2. Inject `ITwilioRestClientUtil` via constructor, and retrieve a `TwilioRestClient`.
```csharp
public class TestClass
{
ITwilioRestClientUtil _twilioRestClientUtil;
public TestClass(ITwilioRestClientUtil twilioRestClientUtil)
{
_twilioRestClientUtil = twilioRestClientUtil;
}
public async ValueTask SendMessage()
{
var message = await MessageResource.CreateAsync(
new PhoneNumber("+11234567890"),
from: new PhoneNumber("+10987654321"),
body: "Hello World!",
client: await _twilioRestClientUtil.Get()
);
Console.WriteLine(message.Sid);
}
```