Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace Activout.RestClient.Helpers.Implementation
*
* Implemented by executing Task<object>.ContinueWith<T>(x => (T)x.Result) using reflection.
*/
[Obsolete("This class is obsolete and will be removed in a future version. Use TaskConverter3Factory instead.")]
internal class TaskConverter : ITaskConverter
{
private static readonly Type ObjectTaskType = typeof(Task<object>);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace Activout.RestClient.Helpers.Implementation
*
* Implemented by creating a TaskCompletionSource<T> and calling SetResult() using reflection.
*/
[Obsolete("This class is obsolete and will be removed in a future version. Use TaskConverter3Factory instead.")]
public class TaskConverter2 : ITaskConverter
{
private readonly Type _type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Activout.RestClient.Helpers.Implementation
{
[Obsolete("This class is obsolete and will be removed in a future version. Use TaskConverter3Factory instead.")]
public class TaskConverter2Factory : ITaskConverterFactory
{
public ITaskConverter CreateTaskConverter(Type actualReturnType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Activout.RestClient.Helpers.Implementation
{
[Obsolete("This class is obsolete and will be removed in a future version. Use TaskConverter3Factory instead.")]
public class TaskConverterFactory : ITaskConverterFactory
{
public ITaskConverter CreateTaskConverter(Type actualReturnType)
Expand Down
20 changes: 17 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ var restClientFactory = Services.CreateRestClientFactory();
var movieReviewService = restClientFactory
.CreateBuilder()
.With(_httpClient)
.WithNewtonsoftJson()
.WithNewtonsoftJson() // or .WithSystemTextJson() for System.Text.Json
.BaseUri(new Uri("https://example.com/movieReviewService"))
.Build<IMovieReviewService>();

Expand Down Expand Up @@ -78,15 +78,30 @@ public static IServiceCollection AddRestClient(this IServiceCollection self)
self.TryAddTransient<IDuckTyping, DuckTyping>();
self.TryAddTransient<IParamConverterManager, ParamConverterManager>();
self.TryAddTransient<IRestClientFactory, RestClientFactory>();
self.TryAddTransient<ITaskConverterFactory, TaskConverter2Factory>();
self.TryAddTransient<ITaskConverterFactory, TaskConverter3Factory>();
return self;
}
```
## JSON serialization support

Since version 5 Activout.RestClient does not depend on any specific JSON library. You must install either the
`Activout.RestClient.Newtonsoft.Json` package (for Newtonsoft.Json support) or the `Activout.RestClient.Json` package (
for System.Text.Json support) to enable JSON serialization and deserialization.

## Breaking changes in version 5

- Replaced `[JsonProperty]` (`JsonPropertyAttribute`) in HTTP form data classes with `[FormKey]` (`FormKeyAttribute`) to
avoid dependency on Newtonsoft.Json.
- Extracted package `Activout.RestClient.Newtonsoft.Json` to make Activout.RestClient independent of Newtonsoft.Json.
- Null values in HTTP form data, header and query parameters now means that no parameter is sent. To send a parameter
without a value, an empty string must be used.
- `IDictionary` and `IDictionary<TKey, TValue>` values for parameters annotated with `[FormParam]`, `[HeaderParam]` or
`[QueryParam]` are no longer serialized using `IParamConverterManager` but instead each key-value pair in the
dictionary is sent as a separate parameter. Both key and value must be non-null values to be sent and
`IParamConverterManager` will be used to convert each value to a string.
- `IParamConverter.CanConvert()` signature changed to take both `Type` and `ParameterInfo` since the `Type` is different
from the `ParameterInfo.ParameterType` for dictionary values.
- Added a `GetConverter(Type type)` method to `IParamConverterManager` to get the converter for a type that is not `ParameterInfo`.

## Breaking changes in version 3

Expand All @@ -113,7 +128,6 @@ public static IServiceCollection AddRestClient(this IServiceCollection self)
## TODO

- Support for cookie parameters, if someone need them
- Maybe extract JSON serialization/deserialization to its own project so that Newtonsoft.Json dependency becomes optional

## Similar projects

Expand Down
Loading