Skip to content

Latest commit

 

History

History
46 lines (32 loc) · 1.87 KB

README.md

File metadata and controls

46 lines (32 loc) · 1.87 KB

Riskfirst.RestClient

CI Build

A fluent inteface used for making RESTful requests.

Getting started

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.

A note on HttpClient

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>();