yanpaulo / RestHttpClient

Simple and flexible REST client built on top of Microsoft's System.Net.HttpClient.
10 stars 1 forks source link

Support for anonymous types #4

Closed AKTheKnight closed 5 years ago

AKTheKnight commented 5 years ago

https://www.reddit.com/r/dotnet/comments/b2nufu/restful_api_access_made_simple_with/eiv5er9

Based on the reddit comment linked below, it would be good to add support for anonymous types such as below:

var todo = new { Title = "", UserId = 0 };
var todoVal = await client.RestGetAnonymousAsync("todos/1", todo);

Not sure if you would like this to be done as:

yanpaulo commented 5 years ago

Well timing is perfect because I'm implementing #5 right now.

It would be really nice to support anonymous types, but don't you think the interface would become a little more difficult to implement?

AKTheKnight commented 5 years ago

I think by using T Deserialize<T>(string content, T type); as the interface method, people can implement is as below if they wanted (This passes all the tests, I just keep it as a separate method so we take advantage of any possible library benefits to anonymous deseralization):

        public T Deserialize<T>(string content, T type)
        {
            return Deserialize<T>(content);
        }
yanpaulo commented 5 years ago

Good news! There is no need to change the interface at all to implement this, as of c7916538cf687f25f89db6bf1242e6923283c9fe @AKTheKnight I see that you've made PR #6 and most of these changes won't be necessary, and so I will take only the tests ok?

AKTheKnight commented 5 years ago

Yes of course, feel free to take whatever :)

yanpaulo commented 5 years ago

@AKTheKnight merged your PR with my own code and it's like this: ab94fd2da1f139dda0f116f3f2144140c5a94ed6 But if I merge it, you won't appear as a contributor. If you would like so, please fix PR #6 and I will merge it instead :)