Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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: 27 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 (12 months ago)
- Default Branch: main
- Last Pushed: 2024-10-29T10:45:08.000Z (4 months ago)
- Last Synced: 2024-10-29T12:43:02.694Z (4 months ago)
- Topics: async, client, csharp, dotnet, rest, restclient, singleton, twilio, twiliorestclientutil, util
- Language: C#
- Homepage: https://soenneker.com
- Size: 1.17 MB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
[![](https://img.shields.io/nuget/v/soenneker.twilio.restclient.svg?style=for-the-badge)](https://www.nuget.org/packages/soenneker.twilio.restclient/)
[![](https://img.shields.io/github/actions/workflow/status/soenneker/soenneker.twilio.restclient/publish-package.yml?style=for-the-badge)](https://github.com/soenneker/soenneker.twilio.restclient/actions/workflows/publish-package.yml)
[![](https://img.shields.io/nuget/dt/soenneker.twilio.restclient.svg?style=for-the-badge)](https://www.nuget.org/packages/soenneker.twilio.restclient/)# ![](https://user-images.githubusercontent.com/4441470/224455560-91ed3ee7-f510-4041-a8d2-3fc093025112.png) 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);
}
```