jgiacomini / Tiny.RestClient

Simpliest Fluent REST client for .NET
MIT License
210 stars 30 forks source link

PostRequest Bearer #101

Closed btbensoft closed 4 years ago

btbensoft commented 4 years ago

Hello,

First at all thank you for this RestClient i love it.

I got some question for you i didnt find same methods form GET or POST, specially for the bearer authentication

GET Version

var response = await client.GetRequest(uriPath)
                    .WithOAuthBearer(_adminToken)
                    .WithTimeout(TimeSpan.FromSeconds(TIMEOUT_SEC))
                    .ExecuteAsync<object>();

POST VERSION

var responseEmail = await client.PostRequest(uriPath, myObject)
                    .WithOAuthBearer(_adminToken) // <=== DO NOT EXIST
                    .WithTimeout(TimeSpan.FromSeconds(TIMEOUT_SEC)) // <=== DO NOT EXIST
                    .ExecuteAsync<object>();

I think i should use like this :

.AddHeader("Authorization", "Bearer " + _adminToken) ?

and how add timeout parameter?

Thanks

jgiacomini commented 4 years ago

Hello @btbensoft,

For post something with customer header and timeout you have to to do like this :

var responseEmail = await client.PostRequest(uriPath)
                    .WithOAuthBearer(_adminToken) // <=== DO NOT EXIST
                    .WithTimeout(TimeSpan.FromSeconds(TIMEOUT_SEC)) // <=== DO NOT EXIST
                    .AddContent(myObject)
                    .ExecuteAsync<object>();

When you defined content, the API remove lot of functionalities to disable the posibility to write inconsistent request. like below :

var responseEmail = await client.PostRequest(uriPath)
                   .GetRequest().
                    .ExecuteAsync<object>();

I will rework the way to restrict methods available after you define a content to have something more usable. :)

If you want help to implement it, I also open for all pullRequests.

jgiacomini commented 4 years ago

I don't know how solve it actually. I have define an interface IRequest : https://github.com/jgiacomini/Tiny.RestClient/blob/develop/Tiny.RestClient/Request/IRequest.cs

When you set a content on your request I restrict methods available by using the IParameterRequest. I want to prevent developer add 2 contents like this :

var aa= await client.PostRequest(uriPath)
                   .PostRequest().
                    .AddContent<object>(object)
                    .AddContent<object>(object)
                    .ExecuteAsync();

I don't know how to solve this API design issue haha

jgiacomini commented 4 years ago

OK I found the way to do it. It will be available in the next release !