FluentRest 9.6.8
See the version list below for details.
dotnet add package FluentRest --version 9.6.8
NuGet\Install-Package FluentRest -Version 9.6.8
<PackageReference Include="FluentRest" Version="9.6.8" />
paket add FluentRest --version 9.6.8
#r "nuget: FluentRest, 9.6.8"
// Install FluentRest as a Cake Addin #addin nuget:?package=FluentRest&version=9.6.8 // Install FluentRest as a Cake Tool #tool nuget:?package=FluentRest&version=9.6.8
FluentRest
Lightweight fluent wrapper over HttpClient to make REST calls easier
Download
The FluentRest library is available on nuget.org via package name FluentRest
.
To install FluentRest, run the following command in the Package Manager Console
PM> Install-Package FluentRest
More information about NuGet package available at https://nuget.org/packages/FluentRest
Development Builds
Development builds are available on the myget.org feed. A development build is promoted to the main NuGet feed when it's determined to be stable.
In your Package Manager settings add the following package source for development builds: http://www.myget.org/F/loresoft/
Features
- Fluent request building
- Fluent form data building
- Automatic deserialization of response content
- Plugin different serialization
- Fake HTTP responses for testing
- Support HttpClientFactory typed client and middleware handlers
Fluent Request
Create a form post request
var client = new HttpClient();
client.BaseAddress = new Uri("http://httpbin.org/", UriKind.Absolute);
var result = await client.PostAsync<EchoResult>(b => b
.AppendPath("Project")
.AppendPath("123")
.FormValue("Test", "Value")
.FormValue("key", "value")
.QueryString("page", 10)
);
Custom authorization header
var client = new HttpClient();
client.BaseAddress = new Uri("https://api.github.com/", UriKind.Absolute);
var result = await client.GetAsync<Repository>(b => b
.AppendPath("repos")
.AppendPath("loresoft")
.AppendPath("FluentRest")
.Header(h => h.Authorization("token", "7ca..."))
);
Use with HttpClientFactory and Retry handler
var services = new ServiceCollection();
services.AddSingleton<IContentSerializer, JsonContentSerializer>();
services.AddHttpClient<GithubClient>(c =>
{
c.BaseAddress = new Uri("https://api.github.com/");
c.DefaultRequestHeaders.Add("Accept", "application/vnd.github.v3+json");
c.DefaultRequestHeaders.Add("User-Agent", "GitHubClient");
})
.AddHttpMessageHandler(() => new RetryHandler());
var serviceProvider = services.BuildServiceProvider();
var client = serviceProvider.GetService<GithubClient>();
var result = await client.GetAsync<Repository>(b => b
.AppendPath("repos")
.AppendPath("loresoft")
.AppendPath("FluentRest")
);
Fake Response
FluentRest.Fake
package adds the ability to fake an HTTP responses by using a custom HttpClientHandler. Faking the HTTP response allows creating unit tests without having to make the actual HTTP call.
To install FluentRest.Fake, run the following command in the Package Manager Console
PM> Install-Package FluentRest.Fake
Fake Response Stores
Fake HTTP responses can be stored in the following message stores. To create your own message store, implement IFakeMessageStore
.
MemoryMessageStore
The memory message store allows composing a JSON response in the unit test. Register the responses on the start of the unit test.
Register a fake response by URL.
MemoryMessageStore.Current.Register(b => b
.Url("https://api.github.com/repos/loresoft/FluentRest")
.StatusCode(HttpStatusCode.OK)
.ReasonPhrase("OK")
.Content(c => c
.Header("Content-Type", "application/json; charset=utf-8")
.Data(responseObject) // object to be JSON serialized
)
);
Use the fake response in a unit test
var serializer = new JsonContentSerializer();
// use memory store by default
var fakeHttp = new FakeMessageHandler();
var httpClient = new HttpClient(fakeHttp, true);
httpClient.BaseAddress = new Uri("https://api.github.com/", UriKind.Absolute);
var client = new FluentClient(httpClient, serializer);
// make HTTP call
var result = await client.GetAsync<Repository>(b => b
.AppendPath("repos")
.AppendPath("loresoft")
.AppendPath("FluentRest")
.Header(h => h.Authorization("token", "7ca..."))
);
Use fake handlers with HttpClientFactory
var services = new ServiceCollection();
services.AddSingleton<IContentSerializer, JsonContentSerializer>();
services.AddSingleton<IFakeMessageStore>(s => MemoryMessageStore.Current);
services
.AddHttpClient<EchoClient>(c => c.BaseAddress = new Uri("http://httpbin.org/"))
.AddHttpMessageHandler(s => new FakeMessageHandler(s.GetService<IFakeMessageStore>(), FakeResponseMode.Fake));
var serviceProvider = services.BuildServiceProvider();
// fake response object
var response = new EchoResult();
response.Url = "http://httpbin.org/post?page=10";
response.Headers["Accept"] = "application/json";
response.QueryString["page"] = "10";
response.Form["Test"] = "Fake";
response.Form["key"] = "value";
// setup fake response
MemoryMessageStore.Current.Register(b => b
.Url("http://httpbin.org/post?page=10")
.StatusCode(HttpStatusCode.OK)
.ReasonPhrase("OK")
.Content(c => c
.Header("Content-Type", "application/json; charset=utf-8")
.Data(response)
)
);
var client = serviceProvider.GetService<EchoClient>();
var result = await client.PostAsync<EchoResult>(b => b
.AppendPath("post")
.FormValue("Test", "Fake")
.FormValue("key", "value")
.QueryString("page", 10)
).ConfigureAwait(false);
FileMessageStore
The file message store allows saving an HTTP call response on the first use. You can then use that saved response for all future unit test runs.
Configure the FluentRest to capture response.
var serializer = new JsonContentSerializer();
// use file store to load from disk
var fakeStore = new FileMessageStore();
fakeStore.StorePath = @".\GitHub\Responses";
var fakeHttp = new FakeMessageHandler(fakeStore, FakeResponseMode.Capture);
var httpClient = new HttpClient(fakeHttp, true);
httpClient.BaseAddress = new Uri("https://api.github.com/", UriKind.Absolute);
var client = new FluentClient(httpClient, serializer);
var result = await client.GetAsync<Repository>(b => b
.AppendPath("repos")
.AppendPath("loresoft")
.AppendPath("FluentRest")
.Header(h => h.Authorization("token", "7ca..."))
);
Use captured response
var serializer = new JsonContentSerializer();
// use file store to load from disk
var fakeStore = new FileMessageStore();
fakeStore.StorePath = @".\GitHub\Responses";
var fakeHttp = new FakeMessageHandler(fakeStore, FakeResponseMode.Fake);
var httpClient = new HttpClient(fakeHttp, true);
httpClient.BaseAddress = new Uri("https://api.github.com/", UriKind.Absolute);
var client = new FluentClient(httpClient, serializer);
var result = await client.GetAsync<Repository>(b => b
.AppendPath("repos")
.AppendPath("loresoft")
.AppendPath("FluentRest")
.Header(h => h.Authorization("token", "7ca..."))
);
Change Log
Version 6.0
- [Breaking] Remove netstandard1.3 support
- add overload for generic AppendPath
- update dependence packages
Version 5.0
- [Breaking] Major refactor to support HttpClientFactory
- [Breaking]
FluentClient
changed to a light wrapper forHttpClient
- [Breaking] Removed
FluentClient.BaseUri
defaults, useHttpClient.BaseAddress
instead - [Breaking] Removed
FluentClient
default headers, useHttpClient
instead - [Breaking] All fluent builder take
HttpRequestMessage
instead ofFluentRequest
- [Breaking] Removed
FluentRequest
andFluentResponse
classes - [Breaking] Removed
FluentRequest.Create
fluent builder - [Breaking] Moved all Fake Response handlers to
FluentRest.Fake
Nuget Package - [Breaking] Removed interceptor support in favor of HttpClientFactory middleware handlers
- Add support for HttpClientFactory typed client and middleware handlers
- Add
FluentRequest.Factory
to support named FluentClient instances
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- System.Net.Http (>= 4.3.4)
- System.Text.Json (>= 7.0.3)
-
.NETStandard 2.1
- System.Net.Http (>= 4.3.4)
- System.Text.Json (>= 7.0.3)
-
net6.0
- System.Net.Http (>= 4.3.4)
- System.Text.Json (>= 7.0.3)
-
net7.0
- System.Net.Http (>= 4.3.4)
- System.Text.Json (>= 7.0.3)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on FluentRest:
Package | Downloads |
---|---|
FluentRest.NewtonsoftJson
Fluent wrapper over HttpClient to make REST calls easier |
|
FluentRest.Factory
Fluent wrapper over HttpClient to make REST calls easier |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
10.0.0 | 90 | 11/13/2024 |
9.9.9 | 632 | 10/9/2024 |
9.9.8 | 1,232 | 8/8/2024 |
9.9.7 | 179 | 8/8/2024 |
9.9.6 | 176 | 8/8/2024 |
9.9.5 | 566 | 7/26/2024 |
9.9.4 | 1,073 | 6/5/2024 |
9.9.3 | 173 | 6/5/2024 |
9.9.2 | 1,339 | 5/1/2024 |
9.9.1 | 258 | 4/26/2024 |
9.9.0 | 2,538 | 3/3/2024 |
9.8.0 | 3,791 | 11/24/2023 |
9.7.0 | 2,228 | 7/28/2023 |
9.6.8 | 1,557 | 7/27/2023 |
9.0.320 | 46,866 | 4/23/2022 |
9.0.299 | 10,470 | 12/22/2021 |
9.0.295 | 774 | 12/3/2021 |
8.0.282 | 1,315 | 11/2/2021 |
8.0.281 | 811 | 10/30/2021 |
7.1.0.274 | 2,100 | 10/21/2021 |
7.1.0.240 | 5,349 | 2/15/2021 |
7.1.0.227 | 7,406 | 11/13/2020 |
7.1.0.216 | 914 | 10/26/2020 |
7.1.0.184 | 5,663 | 6/25/2020 |
7.1.0.183 | 845 | 6/25/2020 |
7.1.0.157 | 61,805 | 4/11/2020 |
7.1.0.132 | 6,897 | 1/24/2020 |
7.1.0.124 | 2,375 | 1/6/2020 |
7.0.0.98 | 7,023 | 9/24/2019 |
6.0.0.90 | 4,496 | 7/18/2019 |
6.0.0.86 | 4,419 | 1/23/2019 |
5.0.0.78 | 48,184 | 5/31/2018 |
4.0.0.72 | 17,486 | 5/30/2018 |
4.0.0.54 | 1,480 | 5/3/2018 |
4.0.0.51 | 1,822 | 3/22/2018 |
4.0.0.41 | 8,041 | 9/14/2017 |
4.0.0.40 | 1,097 | 9/13/2017 |
4.0.0.37 | 1,134 | 9/6/2017 |
3.0.0.33 | 22,631 | 4/12/2017 |
3.0.0.32 | 1,242 | 4/12/2017 |
2.0.0.31 | 2,079 | 8/15/2016 |
2.0.0.29 | 1,202 | 6/29/2016 |
2.0.0.26 | 1,183 | 6/29/2016 |
1.5.0.21 | 2,073 | 3/3/2016 |
1.5.0.20 | 1,186 | 3/2/2016 |
1.4.0.19 | 1,280 | 2/18/2016 |
1.3.0.16 | 1,290 | 1/29/2016 |
1.2.0.13 | 1,956 | 9/29/2015 |
1.2.0.12 | 1,372 | 9/15/2015 |
1.1.0.11 | 1,302 | 9/11/2015 |
1.1.0.10 | 1,283 | 9/10/2015 |
1.0.0.6 | 1,598 | 7/21/2015 |
1.0.0.5 | 1,271 | 7/21/2015 |
1.0.0.4 | 1,280 | 7/20/2015 |