RestMinSharp is a .NET library that provides an easy-to-use interface for making HTTP requests to RESTful APIs. It is built on top of the RestSharp library and aims to simplify the usage of RestSharp, especially when dealing with common use cases.
The RequestResult<T>
class is the base class for all result types returned by RestMinSharp. It provides the following properties:
RawData
: the raw data returned by the API (can be of any type)IsAuthorized
: a boolean indicating whether the request was authorized or notNotifications
: a list of notifications, which can be used to provide additional information about the request resultHasNotifications
: a boolean indicating whether the request result has any notificationsData
: the deserialized response data (of typeT
)
The ERequestResult<T, E>
class extends the RequestResult<T>
class and adds an Error
property of type E
. It can be used when the API returns both response data and error information.
The IRestMinSharpContext
interface defines the main interface of RestMinSharp. It provides the following methods:
AddBearerToken
: adds a bearer token to all requests made through the contextDeleteAsync<T>(string url)
: sends a DELETE request to the specified URL and returns aRequestResult<T>
objectGetAsync<T>(string url)
: sends a GET request to the specified URL and returns aRequestResult<T>
objectGetAsync<T, E>(string url)
: sends a GET request to the specified URL and returns anERequestResult<T, E>
objectGetStreamAsync(string url)
: sends a GET request to the specified URL and returns aMemoryStreamRequestResult
object, which contains the response as aMemoryStream
PatchAsync<T>(string url, List<PatchOperation> operations)
: sends a PATCH request with a list of patch operations to the specified URL and returns aRequestResult<T>
objectPatchAsync<T>(string url, PatchOperation operations)
: sends a PATCH request with a single patch operation to the specified URL and returns aRequestResult<T>
objectPostAsync<T>(string url, object payload)
: sends a POST request with a payload object to the specified URL and returns aRequestResult<T>
objectPostAsync<T>(string url, string json)
: sends a POST request with a JSON payload to the specified URL and returns aRequestResult<T>
objectPostAsync<T, E>(string url, object payload)
: sends a POST request with a payload object to the specified URL and returns anERequestResult<T, E>
objectPostAsync<T>(string url)
: sends a POST request without a payload to the specified URL and returns aRequestResult<T>
objectPostAsync<T, E>(string url)
: sends a POST request without a payload to the specified URL and returns anERequestResult<T, E>
objectPutAsync<T>(string url)
: sends a PUT request without a payload to the specified URL and returns aRequestResult<T>
objectPutAsync<T>(string url, object payload)
: sends a PUT request with a payload object to the specified URL and returns aRequestResult<T>
objectPutAsync<T, E>(string url, object payload)
: sends a PUT request with a payload object to the specified
- .NET Standard 2.0
- RestSharp 106.11.7 or higher
RestMinSharp is available as a NuGet package. You can install it using the NuGet Package Manager in Visual Studio or via the command line:
Install-Package RestMinSharp
RestMinSharp provides an interface called IRestMinSharpContext
that defines a set of methods to interact with RESTful APIs. You can create an instance of this interface using the RestMinSharpContext
class:
IRestMinSharpContext context = new RestMinSharpContext("https://api.example.com/");
Once you have an instance of IRestMinSharpContext
, you can use its methods to send HTTP requests:
var result = await context.GetAsync<MyModel>("my-endpoint");
The library provides support for various HTTP methods and supports deserialization of JSON responses to your models. RestMinSharp also includes an implementation of the IRequestResult<T>
interface, which is a wrapper around the RestSharp IRestResponse
class that provides additional properties such as IsAuthorized
, Notifications
, and Data
.