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/v107/README.md
+43-3Lines changed: 43 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -88,16 +88,40 @@ This way you avoid instantiating `RestRequest` explicitly.
88
88
89
89
This way you can use a pre-configured `HttpClient` or `HttpMessageHandler`, customized for your needs.
90
90
91
-
### Recommended usage
91
+
### Default serializers
92
+
93
+
For JSON, RestSharp will use `JsonSerializer` from the `System.Text.Json` package. This package is now referenced by default, and it is the only dependency of the RestSharp NuGet package.
94
+
95
+
The `Utf8` serializer package is deprecated as the package is not being updated.
96
+
97
+
For XML requests and responses RestSharp uses `DotNetXmlSerializer` and `DotNetXmlDeserializer`.
98
+
Previously used default `XmlSerializer`, `XmlDeserializer`, and `XmlAttrobuteDeserializer` are moved to a separate package `RestSharp.Serializers.Xml`.
99
+
100
+
## Recommended usage
92
101
93
102
`RestClient` should be thread-safe. It holds an instance of `HttpClient` and `HttpMessageHandler` inside.
94
103
Do not instantiate the client for a single call, otherwise you get issues with hanging connections and connection pooling won't be possible.
95
104
96
-
Do use use case-specific typed API clients. Use a single instance of `RestClient` internally in such an API client for making calls.
105
+
Do create typed API clients for your use cases. Use a single instance of `RestClient` internally in such an API client for making calls.
106
+
It would be similar to using typed clients using `HttpClient`, for example:
Do not use one instance of `RestClient` across different API clients.
99
123
100
-
###Presumably solved issues
124
+
## Presumably solved issues
101
125
102
126
The next RestSharp version presumably solves the following issues:
103
127
- Connection pool starvation
@@ -108,3 +132,19 @@ The next RestSharp version presumably solves the following issues:
108
132
- Intermediate certificate issue
109
133
- Uploading large files (use file parameters with `Stream`)
110
134
- Downloading large files (use `DownloadFileStreanAsync`)
135
+
136
+
## Deprecated interfaces
137
+
138
+
The following interfaces are removed from RestSharp:
139
+
-`IRestClient`
140
+
-`IRestRequest`
141
+
-`IRestResponse`
142
+
-`IHttp`
143
+
144
+
### Motivation
145
+
146
+
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.
147
+
148
+
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.
149
+
150
+
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.
0 commit comments