RestSharpHelper

Ecng.Net

Provides helper methods to work with RestSharp requests and responses.

メソッド

AddBodyAsStr
public static void AddBodyAsStr(RestRequest request, string bodyStr)
RestSharpHelper.AddBodyAsStr(request, bodyStr)

Adds a string body to the request with JSON format.

request
The RestRequest to which the body will be added.
bodyStr
The string representation of the body.
DecodeJWT
public static IEnumerable<string> DecodeJWT(string jwt)
result = RestSharpHelper.DecodeJWT(jwt)

Decodes a JSON Web Token (JWT) into its component parts.

jwt
The JWT string.

戻り値: An enumerable of strings representing the decoded parts of the JWT.

Invoke
public static object Invoke(RestRequest request, Uri url, object caller, Action<string, object[]> logVerbose, Func<string, string> contentConverter, bool throwIfEmptyResponse)
result = RestSharpHelper.Invoke(request, url, caller, logVerbose, contentConverter, throwIfEmptyResponse)

Invokes the RestRequest synchronously.

request
The RestRequest to invoke.
url
The URI endpoint for the request.
caller
The caller object for logging context.
logVerbose
An action to log verbose messages.
contentConverter
An optional function to convert the response content.
throwIfEmptyResponse
Indicates whether to throw an exception if the response is empty.

戻り値: The deserialized object response.

Invoke2``1
public static RestResponse<T> Invoke2<T>(RestRequest request, Uri url, object caller, Action<string, object[]> logVerbose, Func<string, string> contentConverter, bool throwIfEmptyResponse)
result = RestSharpHelper.Invoke2(request, url, caller, logVerbose, contentConverter, throwIfEmptyResponse)

Invokes the RestRequest synchronously and returns the full RestResponse of type T.

request
The RestRequest to invoke.
url
The URI endpoint for the request.
caller
The caller object for logging context.
logVerbose
An action to log verbose messages.
contentConverter
An optional function to convert the response content.
throwIfEmptyResponse
Indicates whether to throw an exception if the response is empty.

戻り値: The full RestResponse response.

InvokeAsync
public static Task<object> InvokeAsync(RestRequest request, Uri url, object caller, Action<string, object[]> logVerbose, CancellationToken token, Func<string, string> contentConverter, bool throwIfEmptyResponse)
result = RestSharpHelper.InvokeAsync(request, url, caller, logVerbose, token, contentConverter, throwIfEmptyResponse)

Invokes the RestRequest asynchronously.

request
The RestRequest to invoke.
url
The URI endpoint for the request.
caller
The caller object for logging context.
logVerbose
An action to log verbose messages.
token
The cancellation token.
contentConverter
An optional function to convert the response content.
throwIfEmptyResponse
Indicates whether to throw an exception if the response is empty.

戻り値: A task representing the asynchronous operation, returning the deserialized object response.

InvokeAsync2``1
public static Task<RestResponse<T>> InvokeAsync2<T>(RestRequest request, Uri url, object caller, Action<string, object[]> logVerbose, CancellationToken token, Func<string, string> contentConverter, IAuthenticator auth, bool throwIfEmptyResponse)
result = RestSharpHelper.InvokeAsync2(request, url, caller, logVerbose, token, contentConverter, auth, throwIfEmptyResponse)

Asynchronously invokes the RestRequest and returns the full RestResponse response.

request
The RestRequest to invoke.
url
The URI endpoint for the request.
caller
The caller object for logging context.
logVerbose
An action to log verbose messages.
token
The cancellation token.
contentConverter
An optional function to convert the response content.
auth
An optional authenticator for the request.
throwIfEmptyResponse
Indicates whether to throw an exception if the response is empty.

戻り値: A task representing the asynchronous operation, returning the full RestResponse response.

InvokeAsync3``1
public static Task<RestResponse<T>> InvokeAsync3<T>(RestRequest request, Uri url, object caller, Action<string, object[]> logVerbose, CancellationToken token, Func<string, string> contentConverter, IAuthenticator auth, bool throwIfEmptyResponse, Func<HttpStatusCode, bool> handleErrorStatus)
result = RestSharpHelper.InvokeAsync3(request, url, caller, logVerbose, token, contentConverter, auth, throwIfEmptyResponse, handleErrorStatus)

Asynchronously invokes the RestRequest with extended error handling and returns the full RestResponse response.

request
The RestRequest to invoke.
url
The URI endpoint for the request.
caller
The caller object for logging context.
logVerbose
An action to log verbose messages.
token
The cancellation token.
contentConverter
An optional function to convert the response content.
auth
An optional authenticator for the request.
throwIfEmptyResponse
Indicates whether to throw an exception if the response is empty.
handleErrorStatus
An optional function to handle error HTTP status codes.

戻り値: A task representing the asynchronous operation, returning the full RestResponse response.

InvokeAsync``1
public static Task<T> InvokeAsync<T>(RestRequest request, Uri url, object caller, Action<string, object[]> logVerbose, CancellationToken token, Func<string, string> contentConverter, bool throwIfEmptyResponse)
result = RestSharpHelper.InvokeAsync(request, url, caller, logVerbose, token, contentConverter, throwIfEmptyResponse)

Asynchronously invokes the RestRequest and returns a deserialized response of type T.

request
The RestRequest to invoke.
url
The URI endpoint for the request.
caller
The caller object for logging context.
logVerbose
An action to log verbose messages.
token
The cancellation token.
contentConverter
An optional function to convert the response content.
throwIfEmptyResponse
Indicates whether to throw an exception if the response is empty.

戻り値: A task representing the asynchronous operation, returning the deserialized response of type T.

Invoke``1
public static T Invoke<T>(RestRequest request, Uri url, object caller, Action<string, object[]> logVerbose, Func<string, string> contentConverter, bool throwIfEmptyResponse)
result = RestSharpHelper.Invoke(request, url, caller, logVerbose, contentConverter, throwIfEmptyResponse)

Invokes the RestRequest synchronously and returns a deserialized response of type T.

request
The RestRequest to invoke.
url
The URI endpoint for the request.
caller
The caller object for logging context.
logVerbose
An action to log verbose messages.
contentConverter
An optional function to convert the response content.
throwIfEmptyResponse
Indicates whether to throw an exception if the response is empty.

戻り値: The deserialized response of type T.

RemoveWhere
public static void RemoveWhere(RestRequest request, Func<Parameter, bool> filter)
RestSharpHelper.RemoveWhere(request, filter)

Removes parameters from the request that match the specified filter.

request
The RestRequest to modify.
filter
The filter function to determine which parameters to remove.
SetBearer
public static RestRequest SetBearer(RestRequest client, SecureString token)
result = RestSharpHelper.SetBearer(client, token)

Adds a Bearer authorization header to the RestRequest.

client
The RestRequest to modify.
token
The secure token used for Bearer authentication.

戻り値: The modified RestRequest.

ToError
public static RestSharpException ToError(RestResponse response, string message)
result = RestSharpHelper.ToError(response, message)

Converts a RestResponse into a RestSharpException with additional error details.

response
The RestResponse instance.
message
An optional error message.

戻り値: A new instance of RestSharpException.

ToQueryString
public static string ToQueryString(IEnumerable<Parameter> parameters, bool encodeValue)
result = RestSharpHelper.ToQueryString(parameters, encodeValue)

Converts a collection of parameters into a query string representation.

parameters
The collection of parameters.
encodeValue
Indicates whether the parameter values should be encoded.

戻り値: A query string representing the parameters.