### Perform simple GET request with deserialization Source: https://restsharp.dev/docs/usage/execute Use GetAsync to make a GET call and deserialize the response directly from a resource string. ```csharp var response = await client.GetAsync("endpoint?foo=bar", cancellationToken); ``` -------------------------------- ### Create RestClient with RestClientOptions Source: https://restsharp.dev/docs/usage/client Creates a client using the options object of type RestClientOptions. This example sets a timeout of one second. ```csharp // Creates a client using the options object var options = new RestClientOptions("https://localhost:5000") { Timeout = TimeSpan.FromSeconds(1) }; var client = new RestClient(options); ``` -------------------------------- ### Create a RestRequest with default GET method Source: https://restsharp.dev/docs/usage/request Creates a new RestRequest with the resource sub-path. The default request type is GET. ```csharp var request = new RestRequest(resource); // resource is the sub-path of the client base path ``` -------------------------------- ### Basic RestSharp GET request with authentication Source: https://restsharp.dev/docs/intro Creates a RestClient with basic authentication and performs an asynchronous GET request. The response is a RestResponse containing headers, content, and HTTP status. The cancellation token comes from the caller. ```csharp using RestSharp; using RestSharp.Authenticators; var options = new RestClientOptions("https://api.twitter.com/1.1") { Authenticator = new HttpBasicAuthenticator("username", "password") }; var client = new RestClient(options); var request = new RestRequest("statuses/home_timeline.json"); // The cancellation token comes from the caller. You can still make a call without it. var response = await client.GetAsync(request, cancellationToken); ``` -------------------------------- ### Add a header to a request Source: https://restsharp.dev/docs/usage/request Example of adding a header parameter to a request using the AddHeader method. ```csharp var request = new RestRequest("/path").AddHeader("X-Key", someKey); ``` -------------------------------- ### Perform advanced GET request with object parameters Source: https://restsharp.dev/docs/usage/execute Use an object to compose the resource string where properties matching URL segments are replaced and others are added as query parameters. ```csharp var client = new RestClient("https://example.org"); var args = new { id = "123", foo = "bar" }; // Will make a call to https://example.org/endpoint/123?foo=bar var response = await client.GetAsync("endpoint/{id}", args, cancellationToken); ``` -------------------------------- ### Add query string parameter Source: https://restsharp.dev/docs/usage/request Appends a parameter to the URL as a query string, resulting in a GET request to the specified URL. ```csharp var client = new RestClient("https://search.me"); var request = new RestRequest("search") .AddParameter("foo", "bar"); var response = await client.GetAsync(request); ``` -------------------------------- ### Configure TwitterClient with ASP.NET Core Options Source: https://restsharp.dev/docs/usage/example Alternative constructor implementation using IOptions for dependency injection. ```csharp public record TwitterClientOptions(string ApiKey, string ApiSecret); public TwitterClient(IOptions options) { var tokenRequest = new OAuth2TokenRequest( "https://api.twitter.com/oauth2/token", options.Value.ApiKey, options.Value.ApiSecret ); var opt = new RestClientOptions("https://api.twitter.com/2") { Authenticator = new OAuth2ClientCredentialsAuthenticator(tokenRequest) }; _client = new RestClient(opt); } ``` -------------------------------- ### Add files using extension methods Source: https://restsharp.dev/docs/usage/request Use extension methods to add files from disk, byte arrays, or streams without manually creating a FileParameter. ```csharp // Adds a file from disk AddFile(parameterName, filePath, contentType); // Adds an array of bytes AddFile(parameterName, bytes, fileName, contentType); // Adds a stream returned by the getFile function AddFile(parameterName, getFile, fileName, contentType); ``` -------------------------------- ### RestClient with base URL and configuration Source: https://restsharp.dev/docs/advanced/configuration Provides base URL as first argument and configuration function as second. ```csharp var client = new RestClient("https://localhost:5000/api", options => { options.DisableCharset = true }); ``` -------------------------------- ### Create RestClient with base URL only Source: https://restsharp.dev/docs/usage/client Creates a client with default options to call a given base URL. The base URL can be left empty, in which case absolute paths must be used for each call. ```csharp // Creates a client with default options to call a given base URL var client = new RestClient("https://localhost:5000"); ``` -------------------------------- ### RestSharp GET request with generic deserialization Source: https://restsharp.dev/docs/intro Uses the generic GetAsync overload to automatically deserialize the response into a .NET class. The cancellation token comes from the caller. ```csharp using RestSharp; using RestSharp.Authenticators; var options = new RestClientOptions("https://api.twitter.com/1.1") { Authenticator = new HttpBasicAuthenticator("username", "password") }; var client = new RestClient(options); var request = new RestRequest("statuses/home_timeline.json"); // The cancellation token comes from the caller. You can still make a call without it. var timeline = await client.GetAsync(request, cancellationToken); ``` -------------------------------- ### Create RestClient with RestClientOptions Source: https://restsharp.dev/docs/advanced/configuration Creates a RestClient with custom options, setting DisableCharset to true. ```csharp var options = new RestClientOptions("https://localhost:5000/api") { DisableCharset = true }; var client = new RestClient(options); ``` -------------------------------- ### Configure RedirectOptions in RestClientOptions Source: https://restsharp.dev/docs/advanced/configuration Demonstrates how to instantiate RedirectOptions within RestClientOptions to customize redirect behavior, such as setting the maximum number of redirects and controlling authorization forwarding. ```csharp var options = new RestClientOptions("https://api.example.com") { RedirectOptions = new RedirectOptions { FollowRedirects = true, MaxRedirects = 10, ForwardAuthorization = true, FollowRedirectsToInsecure = false } }; ``` -------------------------------- ### RestSharp JSON GET with GetJsonAsync Source: https://restsharp.dev/docs/intro Calls an API that accepts and returns JSON payloads using the GetJsonAsync extension method, which automatically serializes the request body to JSON and deserializes the response to the specified type. ```csharp var client = new RestClient(options); var timeline = await client.GetJsonAsync("statuses/home_timeline.json", cancellationToken); ``` -------------------------------- ### Create RestClient with simple client factory Source: https://restsharp.dev/docs/usage/client Enables the client factory by setting useClientFactory to true. The factory caches HttpClient instances per distinct base URL, ignoring certain options after the first instance is created. ```csharp var options = new RestClientOptions("https://api.twitter.com/2"); var client = new RestClient(options, useClientFactory: true); ``` -------------------------------- ### RestClient constructor with configuration function Source: https://restsharp.dev/docs/advanced/configuration Constructor that accepts a configuration function to override default options. ```csharp public RestClient( ConfigureRestClient? configureRestClient = null, ConfigureHeaders? configureDefaultHeaders = null, ConfigureSerialization? configureSerialization = null, bool useClientFactory = false ) ``` -------------------------------- ### HeaderInterceptor class overriding BeforeHttpRequest Source: https://restsharp.dev/docs/advanced/interceptors Defines an interceptor that adds a header to the HTTP request message. Overrides BeforeHttpRequest and returns ValueTask.CompletedTask. This is a simple example; RestSharp already provides built-in methods for adding headers. ```csharp // This interceptor adds a header to the request // You'd not normally use this interceptor, as RestSharp already has a method // to add headers to the request class HeaderInterceptor(string headerName, string headerValue) : Interceptors.Interceptor { public override ValueTask BeforeHttpRequest(HttpRequestMessage requestMessage, CancellationToken cancellationToken) { requestMessage.Headers.Add(headerName, headerValue); return ValueTask.CompletedTask; } } ``` -------------------------------- ### Implement TwitterClient class Source: https://restsharp.dev/docs/usage/example Provides the implementation of ITwitterClient, including RestClient configuration with OAuth2 authentication and resource disposal. ```csharp public class TwitterClient : ITwitterClient, IDisposable { readonly RestClient _client; public TwitterClient(string apiKey, string apiKeySecret) { var tokenRequest = new OAuth2TokenRequest( "https://api.twitter.com/oauth2/token", apiKey, apiKeySecret ); var options = new RestClientOptions("https://api.twitter.com/2") { Authenticator = new OAuth2ClientCredentialsAuthenticator(tokenRequest) }; _client = new RestClient(options); } public async Task GetUser(string user) { var response = await _client.GetAsync>( "users/by/username/{user}", new { user } ); return response!.Data; } record TwitterSingleObject(T Data); public void Dispose() { _client?.Dispose(); GC.SuppressFinalize(this); } } ``` -------------------------------- ### Implement Custom Serializer with IRestSerializer Source: https://restsharp.dev/docs/advanced/serialization Create a custom serializer by implementing the IRestSerializer interface, shown here using System.Text.Json. ```csharp public class SimpleJsonSerializer : IRestSerializer { public string? Serialize(object? obj) => obj == null ? null : JsonSerializer.Serialize(obj); public string? Serialize(Parameter bodyParameter) => Serialize(bodyParameter.Value); public T? Deserialize(RestResponse response) => JsonSerializer.Deserialize(response.Content!); public ContentType ContentType { get; set; } = ContentType.Json; public ISerializer Serializer => this; public IDeserializer Deserializer => this; public DataFormat DataFormat => DataFormat.Json; public string[] AcceptedContentTypes => ContentType.JsonAccept; public SupportsContentType SupportsContentType => contentType => contentType.Value.EndsWith("json", StringComparison.InvariantCultureIgnoreCase); } ``` -------------------------------- ### Configure RestClient with lambda Source: https://restsharp.dev/docs/advanced/configuration Configures RestClient using a lambda that sets BaseUrl and DisableCharset. ```csharp var client = new RestClient(options => { options.BaseUrl = new Uri("https://localhost:5000/api"); options.DisableCharset = true; }); ``` -------------------------------- ### Create a RestRequest with POST method Source: https://restsharp.dev/docs/usage/request Creates a new RestRequest with the resource and explicitly sets the HTTP method to POST using the constructor overload. ```csharp var request = new RestRequest(resource, Method.Post); ``` -------------------------------- ### Configure System.Text.Json options Source: https://restsharp.dev/docs/advanced/serialization Use the UseSystemTextJson extension method to provide custom JsonSerializerOptions to the RestClient. ```csharp var client = new RestClient( options, configureSerialization: s => s.UseSystemTextJson(new JsonSerializerOptions {...}) ); ``` -------------------------------- ### Configure FileParameterOptions Source: https://restsharp.dev/docs/usage/request Use FileParameterOptions to customize file upload headers, which is useful for handling non-ASCII filenames. ```csharp var options = new FileParameterOptions { DisableFilenameEncoding = true, DisableFilenameStar = false }; request.AddFile("file", filePath, options: options); ``` -------------------------------- ### Configure CSV Serialization with CsvConfiguration Source: https://restsharp.dev/docs/advanced/serialization Supply a custom CsvConfiguration instance to the UseCsvHelper extension method. ```csharp var client = new RestClient( options, configureSerialization: s => s.UseCsvHelper( new CsvConfiguration(CultureInfo.InvariantCulture) {...} ) ); ``` -------------------------------- ### Configure XML serializer Source: https://restsharp.dev/docs/advanced/serialization Use the UseXmlSerializer extension method to enable the XML serializer, which requires the RestSharp.Serializers.Xml package. ```csharp var client = new RestClient( options, configureSerialization: s => s.UseXmlSerializer() ); ``` -------------------------------- ### Configure CSV Serialization Source: https://restsharp.dev/docs/advanced/serialization Use the UseCsvHelper extension method to configure the RestClient for CSV serialization. ```csharp var client = new RestClient( options, configureSerialization: s => s.UseCsvHelper() ); ``` -------------------------------- ### Add a cookie with explicit path and domain Source: https://restsharp.dev/docs/usage/request Use the four-parameter AddCookie overload to explicitly define the path and domain for the cookie. ```csharp request.AddCookie("foo", "bar", "/path", "example.com"); ``` -------------------------------- ### Configure OAuth2ClientCredentialsAuthenticator Source: https://restsharp.dev/docs/usage/example Sets up an OAuth2TokenRequest and assigns it to the RestClientOptions Authenticator. The authenticator manages token lifecycle automatically using an internal HttpClient. ```csharp var tokenRequest = new OAuth2TokenRequest( "https://api.twitter.com/oauth2/token", apiKey, apiKeySecret ); var options = new RestClientOptions("https://api.twitter.com/2") { Authenticator = new OAuth2ClientCredentialsAuthenticator(tokenRequest) }; ``` -------------------------------- ### OAuth1 0-legged Source: https://restsharp.dev/docs/advanced/authenticators Perform 0-legged OAuth by providing null for the consumerSecret in the ForAccessToken method. ```csharp var authenticator = OAuth1Authenticator.ForAccessToken( consumerKey, null, oauthToken, oauthTokenSecret ); ``` -------------------------------- ### Default NewtonsoftJson settings Source: https://restsharp.dev/docs/advanced/serialization The default configuration for Newtonsoft.Json includes specific settings for contract resolution, null handling, and formatting. ```csharp JsonSerializerSettings DefaultSettings = new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver(), DefaultValueHandling = DefaultValueHandling.Include, TypeNameHandling = TypeNameHandling.None, NullValueHandling = NullValueHandling.Ignore, Formatting = Formatting.None, ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor }; ``` -------------------------------- ### Add RestSharp NuGet package Source: https://restsharp.dev/docs/intro Command to add the RestSharp NuGet package to a .NET project using the dotnet CLI. ```bash dotnet add package RestSharp ``` -------------------------------- ### Configure a custom serializer Source: https://restsharp.dev/docs/advanced/serialization Use the configureSerialization parameter in the RestClient constructor to register a custom serializer implementation. ```csharp var client = new RestClient( options, configureSerialization: s => s.UseSerializer(() => new CustomSerializer()) ); ``` -------------------------------- ### RestClient constructor signature Source: https://restsharp.dev/docs/advanced/configuration Primary constructor for RestClient. Accepts RestClientOptions and optional delegates for default headers, serialization, and client factory usage. ```csharp public RestClient( RestClientOptions options, ConfigureHeaders? configureDefaultHeaders = null, ConfigureSerialization? configureSerialization = null, bool useClientFactory = false ) ``` -------------------------------- ### Add a file using FileParameter Source: https://restsharp.dev/docs/usage/request Use the AddFile method with a FileParameter object to attach a file to a request. ```csharp request.AddFile(fileParameter); ``` -------------------------------- ### Migrating hook to CompatibilityInterceptor Source: https://restsharp.dev/docs/advanced/interceptors Shows how to migrate the deprecated OnBeforeDeserialization hook to an interceptor using CompatibilityInterceptor. The interceptor is added to the request's Interceptors collection. ```csharp var request = new RestRequest("success") { Interceptors = [new CompatibilityInterceptor { OnBeforeDeserialization = _ => throw new Exception(exceptionMessage) }] }; ``` -------------------------------- ### Configure NewtonsoftJson serializer Source: https://restsharp.dev/docs/advanced/serialization Use the UseNewtonsoftJson extension method to enable the Newtonsoft.Json serializer via the RestSharp.Serializers.NewtonsoftJson package. ```csharp var client = new RestClient( options, configureSerialization: s => s.UseNewtonsoftJson() ); ``` -------------------------------- ### Implement Custom IAuthenticator Source: https://restsharp.dev/docs/advanced/authenticators Demonstrates registering a custom class that implements IAuthenticator with RestClientOptions. The Authenticate method is invoked before request execution, allowing full access to request data. ```csharp var authenticator = new SuperAuthenticator(); // implements IAuthenticator var options = new RestClientOptions("https://example.com") { Authenticator = authenticator }; var client = new RestClient(options); ``` -------------------------------- ### Adding an interceptor to the client via RestClientOptions Source: https://restsharp.dev/docs/advanced/interceptors Creates a RestClient with an interceptor added to the client options. The interceptor will be executed for every request made by that client. ```csharp var options = new RestClientOptions("https://api.example.com") { Interceptors = [new HeaderInterceptor("Authorization", token)] }; var client = new RestClient(options); ``` -------------------------------- ### Add parameters using AddObject Source: https://restsharp.dev/docs/usage/request Collects parameters in an object and adds them to the request in one call. This works with primitive types and collections of primitive types. ```csharp var params = new { status = 1, priority = "high", ids = new [] { "123", "456" } }; request.AddObject(params); ``` ```csharp request.AddParameter("status", 1); request.AddParameter("priority", "high"); request.AddParameter("ids", "123,456"); ``` -------------------------------- ### AddParameter with explicit CultureInfo Source: https://restsharp.dev/docs/advanced/configuration Demonstrates how to pass a specific CultureInfo to AddParameter to override the default invariant culture formatting. ```csharp request.AddParameter("price", 1234.56, culture: new CultureInfo("da-DK")); // Sends: price=1234,56 ``` -------------------------------- ### Add default query string parameter to client Source: https://restsharp.dev/docs/usage/request Adds a parameter to every request made by the client instance. ```csharp client.AddDefaultQueryParameter("foo", "bar"); ``` -------------------------------- ### OAuth1 xAuth Source: https://restsharp.dev/docs/advanced/authenticators Create an xAuth authenticator using OAuth1Authenticator.ForClientAuthentication to exchange credentials directly for an access token. ```csharp var authenticator = OAuth1Authenticator.ForClientAuthentication( consumerKey, consumerSecret, username, password ); ``` -------------------------------- ### Add header parameter methods Source: https://restsharp.dev/docs/usage/request Lists the available methods to add header parameters to a request. AddHeader converts the value to string when using the generic overload, and AddOrUpdateHeader replaces an existing header. ```csharp AddHeader(string name, string value); AddHeader(string name, T value); // value will be converted to string AddOrUpdateHeader(string name, string value); // replaces the header if it already exists ``` -------------------------------- ### ExecuteGetAsync and other method-specific overloads Source: https://restsharp.dev/docs/usage/execute Overloads that set the HTTP method for you. They return RestResponse and do not throw on server errors, allowing graceful handling of remote errors. ```csharp Task ExecuteGetAsync(RestRequest request, CancellationToken cancellationToken) Task ExecutePostAsync(RestRequest request, CancellationToken cancellationToken) Task ExecutePutAsync(RestRequest request, CancellationToken cancellationToken) Task ExecuteDeleteAsync(RestRequest request, CancellationToken cancellationToken) Task ExecuteHeadAsync(RestRequest request, CancellationToken cancellationToken) Task ExecuteOptionsAsync(RestRequest request, CancellationToken cancellationToken) ``` -------------------------------- ### Configure JwtAuthenticator Source: https://restsharp.dev/docs/advanced/authenticators Initializes a JwtAuthenticator with a token and assigns it to RestClientOptions. This automatically adds an Authorization header with the Bearer scheme to requests. ```csharp var authenticator = new JwtAuthenticator(myToken); var options = new RestClientOptions("https://example.com") { Authenticator = authenticator }; var client = new RestClient(options); ``` -------------------------------- ### ConfigureMessageHandler with MockHttp Source: https://restsharp.dev/docs/advanced/configuration Sets ConfigureMessageHandler to replace the default handler with a MockHttp handler for testing. The handler created by RestSharp is ignored. ```csharp var mockHttp = new MockHttpMessageHandler(); // Configure the MockHttp handler to do the checks ... var options = new RestClientOptions(Url) { ConfigureMessageHandler = _ => mockHttp }; using var client = new RestClient(options); ``` -------------------------------- ### Using OnBeforeRequest hook before migration Source: https://restsharp.dev/docs/advanced/interceptors Shows the old way of using the OnBeforeDeserialization hook on a RestRequest. This hook is deprecated and should be migrated to interceptors. ```csharp var request = new RestRequest("success"); request.OnBeforeDeserialization += _ => throw new Exception(exceptionMessage); ``` -------------------------------- ### Add default parameter to client Source: https://restsharp.dev/docs/usage/request Use AddDefaultParameter to include a parameter in every request made by the client. ```csharp client.AddDefaultParameter("foo", "bar"); ``` -------------------------------- ### OAuth1 access token with verifier Source: https://restsharp.dev/docs/advanced/authenticators Use the overload of ForAccessToken that accepts a verifier value if the second step of the OAuth1 flow provided one. ```csharp var authenticator = OAuth1Authenticator.ForAccessToken( consumerKey, consumerSecret, oauthToken, oauthTokenSecret, verifier ); ``` -------------------------------- ### OAuth1 access token Source: https://restsharp.dev/docs/advanced/authenticators Use OAuth1Authenticator.ForAccessToken to retrieve an access token in the third step of a 3-legged OAuth1 flow. ```csharp var authenticator = OAuth1Authenticator.ForAccessToken( consumerKey, consumerSecret, oauthToken, oauthTokenSecret ); var options = new RestClientOptions("https://api.twitter.com") { Authenticator = authenticator }; var client = new RestClient(options); var request = new RestRequest("oauth/access_token"); ``` -------------------------------- ### IRestClient GetAsync and other non-deserializing extensions Source: https://restsharp.dev/docs/usage/execute IRestClient extensions for making requests without deserialization. They throw an exception if the server returns an error, even if the client is configured to not throw exceptions. ```csharp Task GetAsync(RestRequest request, CancellationToken cancellationToken) Task PostAsync(RestRequest request, CancellationToken cancellationToken) Task PutAsync(RestRequest request, CancellationToken cancellationToken) Task PatchAsync(RestRequest request, CancellationToken cancellationToken) Task DeleteAsync(RestRequest request, CancellationToken cancellationToken) Task HeadAsync(RestRequest request, CancellationToken cancellationToken) Task OptionsAsync(RestRequest request, CancellationToken cancellationToken) ``` -------------------------------- ### GetAsync and other deserializing extensions Source: https://restsharp.dev/docs/usage/execute Extensions that return only the deserialized object. They throw an exception if the server returns an error, as there is no other way to surface the error to the caller. ```csharp Task GetAsync(RestRequest request, CancellationToken cancellationToken) Task PostAsync(RestRequest request, CancellationToken cancellationToken) Task PutAsync(RestRequest request, CancellationToken cancellationToken) Task PatchAsync(RestRequest request, CancellationToken cancellationToken) Task DeleteAsync(RestRequest request, CancellationToken cancellationToken) Task HeadAsync(RestRequest request, CancellationToken cancellationToken) Task OptionsAsync(RestRequest request, CancellationToken cancellationToken) ``` -------------------------------- ### Register RestClient as a singleton in Blazor Source: https://restsharp.dev/docs/usage/client Register the RestClient instance globally in your Blazor application using the HttpClient constructor to avoid platform-specific limitations. ```csharp builder.Services.AddSingleton(new RestClient(new HttpClient())); ``` -------------------------------- ### RestClient constructors for custom HttpClient Source: https://restsharp.dev/docs/advanced/configuration These constructors accept an existing HttpClient and optional RestClientOptions or configuration functions. The disposeHttpClient parameter defaults to false, meaning the HttpClient is not disposed by RestClient. ```csharp // Create a client using an existing HttpClient and RestClientOptions (optional) public RestClient( HttpClient httpClient, RestClientOptions? options, bool disposeHttpClient = false, ConfigureSerialization? configureSerialization = null ) // Create a client using an existing HttpClient and optional RestClient configuration function public RestClient( HttpClient httpClient, bool disposeHttpClient = false, ConfigureRestClient? configureRestClient = null, ConfigureSerialization? configureSerialization = null ) ``` -------------------------------- ### Multipart form-data parameter structure Source: https://restsharp.dev/docs/usage/request When files are attached, parameters are sent as part of a multipart/form-data request. ```http Content-Type: text/plain; charset=utf-8 Content-Disposition: form-data; name="parameterName" ParameterValue ``` -------------------------------- ### OAuth2TokenAuthenticator with custom token provider Source: https://restsharp.dev/docs/advanced/authenticators Uses OAuth2TokenAuthenticator with an async delegate to handle non-standard token flows. ```csharp var options = new RestClientOptions("https://api.example.com") { Authenticator = new OAuth2TokenAuthenticator(async cancellationToken => { var token = await myCustomTokenService.GetTokenAsync(cancellationToken); return new OAuth2Token(token.Value, token.ExpiresAt); }) }; using var client = new RestClient(options); ``` -------------------------------- ### Add a pre-serialized string body with AddStringBody Source: https://restsharp.dev/docs/usage/request Use AddStringBody for pre-serialized payloads, ensuring you specify the content type for the remote endpoint. ```csharp const json = "{ data: { foo: \"bar\" } }"; request.AddStringBody(json, ContentType.Json); ``` -------------------------------- ### Add a cookie with inferred domain Source: https://restsharp.dev/docs/usage/request Use the two-parameter AddCookie method to add a cookie where the domain is inferred from the request URL at execution time. ```csharp request.AddCookie("foo", "bar"); ``` -------------------------------- ### RestClient constructor for custom HttpMessageHandler Source: https://restsharp.dev/docs/advanced/configuration This constructor creates a new HttpClient using the provided message handler. The disposeHandler parameter defaults to true, so the handler is disposed with the client; set it to false to keep the handler. ```csharp public RestClient( HttpMessageHandler handler, bool disposeHandler = true, ConfigureRestClient? configureRestClient = null, ConfigureSerialization? configureSerialization = null ) ``` -------------------------------- ### Perform POST request with JSON response Source: https://restsharp.dev/docs/usage/execute Use PostJsonAsync to post an object as JSON and deserialize the response into a specific type. ```csharp var request = new CreateOrder("123", "foo", 10100); // Will post the request object as JSON to "orders" and returns a // JSON response deserialized to OrderCreated var result = client.PostJsonAsync("orders", request, cancellationToken); ```