A fluent inteface used for making RESTful requests.
Install the package from Nuget.org
PM> Install-Package RiskFirst.RestClient
Make a simple RESTful GET
request
var myServiceUri = new Uri("https://myservice.com");
var response = myServiceUri.AsRestRequest()
.GetAsync()
.ReceiveAsync();
The above will return an instance of HttpResponseMessage
which can be used to read the status code, or any other property. You can also receive a JSON
response for your custom object.
var myServiceUri = new Uri("https://myservice.com");
var response = myServiceUri.AsRestRequest()
.GetAsync()
.ReceiveJsonAsync<MyClass>();
The above will return an instance of MyClass
deserialized from the response message, or throw a RestResponseException
on a non-success response.
This library uses a static instance of HttpClient
for all requests, as per the advice in this advice however clients of this library are free to provide their own instance of HttpClient
if they wish. You should be aware of this post regarding the use of a static HttpClient
This is an optional parameters on all request methods:
var myServiceUri = new Uri("https://myservice.com");
var response = myServiceUri.AsRestRequest()
.GetAsync(myHttpClientInstance)
.ReceiveJsonAsync<MyClass>();