Skip to content

Commit d284f78

Browse files
committed
Related changes in the docs
Fixed the failing parameters parsing tests
1 parent cdc020d commit d284f78

File tree

4 files changed

+11
-18
lines changed

4 files changed

+11
-18
lines changed

docs/.vuepress/config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module.exports = {
1111
themeConfig: {
1212
logo: "/restsharp.png",
1313
navbar: [
14-
{text: "Migration to v107", link: "/v107/"},
14+
{text: "Migration from legacy", link: "/v107/"},
1515
{text: "Documentation", link: "/intro.html"},
1616
{text: "Get help", link: "/support/"},
1717
{text: "NuGet", link: "https://nuget.org/packages/RestSharp"}
@@ -34,7 +34,7 @@ module.exports = {
3434
"/v107/": [
3535
{
3636
text: "",
37-
header: "Migration to v107",
37+
header: "Migration from legacy",
3838
children: [
3939
"/v107/README.md"
4040
]

docs/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ heroText: RestSharp
55
tagline: Probably, the most popular REST API client library for .NET
66
actions:
77
- text: Get Started →
8-
link: /v107/
8+
link: /intro.html
99
features:
1010
- title: Serialization
1111
details: JSON, XML and custom serialization and deserialization
@@ -24,7 +24,7 @@ footer: Apache 2.0 Licensed | Copyright (c) .NET Foundation and Contributors
2424

2525
RestSharp is probably the most popular HTTP client library for .NET. Featuring automatic serialization and deserialization, request and response type detection, variety of authentications and other useful features, it is being used by hundreds of thousands of projects.
2626

27-
RestSharp passed over 165 million downloads on NuGet, with average daily download count close to 42,000. It's being used by many popular OSS projects, including Roslyn and Swagger.
27+
RestSharp passed over 190 million downloads on NuGet, with average daily download count over 43,000. It's being used by many popular OSS projects, including Roslyn and Swagger.
2828

2929
Supported by [AWS](https://aws.amazon.com/developer/language/net/solutions/).
3030
<div style="text-align: center;"><a href="https://aws.amazon.com"><img src="/aws_logo.png" alt="AWS logo"></a></div>

docs/v107/README.md

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
---
2-
title: RestSharp Next (v107)
2+
title: RestSharp Next (v107+)
33
---
44

5-
## RestSharp v107
5+
## RestSharp v107+
66

7-
The latest version of RestSharp is v107. It's a major upgrade, which contains quite a few breaking changes.
7+
RestSharp got a major upgrade in v107, which contains quite a few breaking changes.
88

99
The most important change is that RestSharp stop using the legacy `HttpWebRequest` class, and uses well-known 'HttpClient' instead.
1010
This move solves lots of issues, like hanging connections due to improper `HttpClient` instance cache, updated protocols support, and many other problems.
@@ -17,7 +17,7 @@ Finally, most of the interfaces are now gone.
1717

1818
### RestClient and options
1919

20-
The `IRestClient` interface is deprecated. You will be using the `RestClient` class instance.
20+
The `IRestClient` interface is deprecated in v107, but brought back in v109. The new interface, however, has a much smaller API compared to previous versions. You will be using the `RestClient` class instance.
2121

2222
Most of the client options are moved to `RestClientOptions`. If you can't find the option you used to set on `IRestClient`, check the options, it's probably there.
2323

@@ -187,23 +187,16 @@ The next RestSharp version presumably solves the following issues:
187187
## Deprecated interfaces
188188

189189
The following interfaces are removed from RestSharp:
190-
- `IRestClient`
191190
- `IRestRequest`
192191
- `IRestResponse`
193192
- `IHttp`
194193

195-
### Motivation
196-
197-
All the deprecated interfaces had only one implementation in RestSharp, so those interfaces were abstracting nothing. It is now unclear what was the purpose for adding those interfaces initially.
198-
199-
What about mocking it, you might ask? The answer is: what would you do if you use a plain `HttpClient` instance? It doesn't implement any interface for the same reason - there's nothing to abstract, and there's only one implementation. We don't recommend mocking `RestClient` in your tests when you are testing against APIs that are controlled by you or people in your organisation. Test your clients against the real thing, as REST calls are I/O-bound. Mocking REST calls is like mocking database calls, and lead to a lot of issues in production even if all your tests pass against mocks.
200-
201-
As mentioned in [Recommended usage](#recommended-usage), we advise against using `RestClient` in the application code, and advocate wrapping it inside particular API client classes. Those classes would be under your control, and you are totally free to use interfaces there. If you absolutely must mock, you can mock your interfaces instead.
202-
203194
### Mocking
204195

205196
Mocking an infrastructure component like RestSharp (or HttpClient) is not the best idea. Even if you check that all the parameters are added correctly to the request, your "unit test" will only give you a false sense of safety that your code actually works. But, you have no guarantee that the remote server will accept your request, or if you can handle the actual response correctly.
206197

198+
However, since v109 you can still mock the `IRestClient` interface, but you only need to implement the `ExecuteAsync` method. The `ExecuteAsync` method is the only one that actually makes a call to the remote server. All other methods are just wrappers around it.
199+
207200
The best way to test HTTP calls is to make some, using the actual service you call. However, you might still want to check if your API client forms requests in a certain way. You might also be sure about what the remote server responds to your calls with, so you can build a set of JSON (or XML) responses, so you can simulate remote calls.
208201

209202
It is perfectly doable without using interfaces. As RestSharp uses `HttpClient` internally, it certainly uses `HttpMessageHandler`. Features like delegating handlers allow you to intercept the request pipeline, inspect the request, and substitute the response. You can do it yourself, or use a library like [MockHttp](https://github.com/richardszalay/mockhttp). They have an example provided in the repository README, so we have changed it for RestClient here:

test/RestSharp.Tests/ObjectParserTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public void ShouldProduceMultipleParametersForArray() {
3131
SomeIds = new[] { 1, 2, 3 }
3232
};
3333
var expected = request.SomeIds.Select(x => ("ids[]", x.ToString()));
34-
var parsed = request.GetProperties();
34+
var parsed = request.GetProperties().Select(x => (x.Name, x.Value));
3535

3636
parsed.Should().BeEquivalentTo(expected);
3737
}

0 commit comments

Comments
 (0)