-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' of https://github.com/fseidl-bauradar/RestSharp in…
…to dev
- Loading branch information
Showing
22 changed files
with
1,062 additions
and
816 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
// Copyright (c) .NET Foundation and Contributors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
namespace RestSharp; | ||
|
||
public static partial class RestClientExtensions { | ||
/// <summary> | ||
/// Executes a DELETE-style request asynchronously, authenticating if needed | ||
/// </summary> | ||
/// <param name="client"></param> | ||
/// <param name="request">Request to be executed</param> | ||
/// <param name="cancellationToken">Cancellation token</param> | ||
public static Task<RestResponse> ExecuteDeleteAsync(this IRestClient client, RestRequest request, CancellationToken cancellationToken = default) | ||
=> client.ExecuteAsync(request, Method.Delete, cancellationToken); | ||
|
||
/// <summary> | ||
/// Executes a DELETE-style synchronously, authenticating if needed | ||
/// </summary> | ||
/// <param name="client"></param> | ||
/// <param name="request">Request to be executed</param> | ||
public static RestResponse ExecuteDelete(this IRestClient client, RestRequest request) | ||
=> AsyncHelpers.RunSync(() => client.ExecuteAsync(request, Method.Delete)); | ||
|
||
/// <summary> | ||
/// Executes a DELETE-style request asynchronously, authenticating if needed. | ||
/// The response content then gets deserialized to T. | ||
/// </summary> | ||
/// <typeparam name="T">Target deserialization type</typeparam> | ||
/// <param name="client"></param> | ||
/// <param name="request">Request to be executed</param> | ||
/// <param name="cancellationToken">The cancellation token</param> | ||
/// <returns>Deserialized response content</returns> | ||
public static Task<RestResponse<T>> ExecuteDeleteAsync<T>( | ||
this IRestClient client, | ||
RestRequest request, | ||
CancellationToken cancellationToken = default | ||
) | ||
=> client.ExecuteAsync<T>(request, Method.Delete, cancellationToken); | ||
|
||
/// <summary> | ||
/// Executes a DELETE-style request synchronously, authenticating if needed. | ||
/// The response content then gets deserialized to T. | ||
/// </summary> | ||
/// <typeparam name="T">Target deserialization type</typeparam> | ||
/// <param name="client"></param> | ||
/// <param name="request">Request to be executed</param> | ||
/// <returns>Deserialized response content</returns> | ||
public static RestResponse<T> ExecuteDelete<T>(this IRestClient client, RestRequest request) | ||
=> AsyncHelpers.RunSync(() => client.ExecuteAsync<T>(request, Method.Delete)); | ||
|
||
/// <summary> | ||
/// Execute the request using DELETE HTTP method. Exception will be thrown if the request does not succeed. | ||
/// The response data is deserialized to the Data property of the returned response object. | ||
/// </summary> | ||
/// <param name="client">RestClient instance</param> | ||
/// <param name="request">The request</param> | ||
/// <param name="cancellationToken">Cancellation token</param> | ||
/// <typeparam name="T">Expected result type</typeparam> | ||
/// <returns></returns> | ||
public static async Task<T?> DeleteAsync<T>(this IRestClient client, RestRequest request, CancellationToken cancellationToken = default) { | ||
var response = await client.ExecuteAsync<T>(request, Method.Delete, cancellationToken).ConfigureAwait(false); | ||
return response.ThrowIfError().Data; | ||
} | ||
|
||
/// <summary> | ||
/// Execute the request using DELETE HTTP method. Exception will be thrown if the request does not succeed. | ||
/// The response data is deserialized to the Data property of the returned response object. | ||
/// </summary> | ||
/// <param name="client">RestClient instance</param> | ||
/// <param name="request">The request</param> | ||
/// <typeparam name="T">Expected result type</typeparam> | ||
/// <returns></returns> | ||
public static T? Delete<T>(this IRestClient client, RestRequest request) => AsyncHelpers.RunSync(() => client.DeleteAsync<T>(request)); | ||
|
||
/// <summary> | ||
/// Execute the request using DELETE HTTP method. Exception will be thrown if the request does not succeed. | ||
/// </summary> | ||
/// <param name="client">RestClient instance</param> | ||
/// <param name="request">The request</param> | ||
/// <param name="cancellationToken">Cancellation token</param> | ||
/// <returns></returns> | ||
public static async Task<RestResponse> DeleteAsync(this IRestClient client, RestRequest request, CancellationToken cancellationToken = default) { | ||
var response = await client.ExecuteAsync(request, Method.Delete, cancellationToken).ConfigureAwait(false); | ||
return response.ThrowIfError(); | ||
} | ||
|
||
/// <summary> | ||
/// Execute the request using DELETE HTTP method. Exception will be thrown if the request does not succeed. | ||
/// </summary> | ||
/// <param name="client">RestClient instance</param> | ||
/// <param name="request">The request</param> | ||
/// <returns></returns> | ||
public static RestResponse Delete(this IRestClient client, RestRequest request) => AsyncHelpers.RunSync(() => client.DeleteAsync(request)); | ||
} |
Oops, something went wrong.