https://github.com/riskfirst/riskfirst.restclient
https://github.com/riskfirst/riskfirst.restclient
Last synced: 9 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/riskfirst/riskfirst.restclient
- Owner: riskfirst
- License: mit
- Created: 2017-05-24T08:15:48.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2022-12-13T09:39:20.000Z (over 3 years ago)
- Last Synced: 2025-08-13T09:49:47.372Z (10 months ago)
- Language: C#
- Size: 49.8 KB
- Stars: 5
- Watchers: 14
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Riskfirst.RestClient

A [fluent inteface](https://en.wikipedia.org/wiki/Fluent_interface) used for making RESTful requests.
### Getting started
Install the package from [Nuget.org](https://www.nuget.org/packages/riskfirst.restclient)
```powershell
PM> Install-Package RiskFirst.RestClient
```
Make a simple RESTful `GET` request
```csharp
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.
```csharp
var myServiceUri = new Uri("https://myservice.com");
var response = myServiceUri.AsRestRequest()
.GetAsync()
.ReceiveJsonAsync();
```
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](https://aspnetmonsters.com/2016/08/2016-08-27-httpclientwrong/) 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](http://byterot.blogspot.co.uk/2016/07/singleton-httpclient-dns.html)
This is an optional parameters on all request methods:
```csharp
var myServiceUri = new Uri("https://myservice.com");
var response = myServiceUri.AsRestRequest()
.GetAsync(myHttpClientInstance)
.ReceiveJsonAsync();
```