reactiveui / refit

The automatic type-safe REST library for .NET Core, Xamarin and .NET. Heavily inspired by Square's Retrofit library, Refit turns your REST API into a live interface.
https://reactiveui.github.io/refit/
MIT License
8.47k stars 745 forks source link

Dynamic Querystring Parameters support for POST requests #592

Closed whoiskevinrich closed 5 years ago

whoiskevinrich commented 5 years ago

I'm attempting to use Refit against the Amazon MWS API, but have one hurdle:

The Amazon MWS API accepts Query Parameters on a POST request for some calls. Here is some AWS Documentation.

From what I can see, Refit will bind this:


[Get("/")]
Task<MyResult> GetFeedSubmissions(MyRequest parameters);

but not this:


[Post("/")]
Task<MyResult> GetFeedSubmissions(MyRequest parameters);

AWS is a bit screwy in terms of how this works, but is it possible to add dynamic query support for POST requests?

bennor commented 5 years ago

This definitely sounds like something Refit supports. Have a look at form posts in the README.

whoiskevinrich commented 5 years ago

I tried using both the Dictionary and Dynamic Querystring object approaches shown in the readme, without success.

The call is not for a form post, but rather a POST request with a querystring.

Here is the raw(ish) working request from their Scratchpad (with redacted info):

POST /?AWSAccessKeyId=*******
  &Action=GetFeedSubmissionList
  &Merchant=*******
  &MWSAuthToken=*******
  &SignatureVersion=2
  &Timestamp=*******
  &Version=*******
  &Signature=*******
  &SignatureMethod=HmacSHA256
  &FeedProcessingStatusList.Status.1=_SUBMITTED_ HTTP/1.1
Host: mws.amazonservices.com
x-amazon-user-agent: AmazonJavascriptScratchpad/1.0 (Language=Javascript)
Content-Type: text/xml

Also, I should point out, I can make the request just fine using the format of:

[Post("/?Action={GetFeedSubmission}&Merchant={...} ... ")]

But I'd like to leverage the object approach in order to add validation.

bennor commented 5 years ago

Ah I see. Not sure why that doesn't work.

whoiskevinrich commented 5 years ago

I noticed this, while probing the RequestBuilderImplementation.cs code:

        static readonly ISet<HttpMethod> bodylessMethods = new HashSet<HttpMethod>
        {
            HttpMethod.Get,
            HttpMethod.Head
        };

The call in question is bodyless, is it possible this is related?

jamiehowarth0 commented 5 years ago

@whoiskevinrich I believe this is now fixed by the latest release: https://github.com/reactiveui/refit/pull/629