You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/README.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ heroText: RestSharp
5
5
tagline: Probably, the most popular REST API client library for .NET
6
6
actions:
7
7
- text: Get Started →
8
-
link: /v107/
8
+
link: /intro.html
9
9
features:
10
10
- title: Serialization
11
11
details: JSON, XML and custom serialization and deserialization
@@ -24,7 +24,7 @@ footer: Apache 2.0 Licensed | Copyright (c) .NET Foundation and Contributors
24
24
25
25
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.
26
26
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.
28
28
29
29
Supported by [AWS](https://aws.amazon.com/developer/language/net/solutions/).
Copy file name to clipboardExpand all lines: docs/v107/README.md
+6-13Lines changed: 6 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,10 @@
1
1
---
2
-
title: RestSharp Next (v107)
2
+
title: RestSharp Next (v107+)
3
3
---
4
4
5
-
## RestSharp v107
5
+
## RestSharp v107+
6
6
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.
8
8
9
9
The most important change is that RestSharp stop using the legacy `HttpWebRequest` class, and uses well-known 'HttpClient' instead.
10
10
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.
17
17
18
18
### RestClient and options
19
19
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.
21
21
22
22
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.
23
23
@@ -187,23 +187,16 @@ The next RestSharp version presumably solves the following issues:
187
187
## Deprecated interfaces
188
188
189
189
The following interfaces are removed from RestSharp:
190
-
-`IRestClient`
191
190
-`IRestRequest`
192
191
-`IRestResponse`
193
192
-`IHttp`
194
193
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
-
203
194
### Mocking
204
195
205
196
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.
206
197
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
+
207
200
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.
208
201
209
202
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:
0 commit comments