Refit: Dynamic querystring!

Created on 24 May 2017  路  25Comments  路  Source: reactiveui/refit

Hi,
I've got an endpoint which has about 15 query string parameters for filtering purposes. As they are optional parameters, there will be a lot of parameter combination so overloads are useless and Also I should avoid setting null-value parameters as it does affect on the result.
I searched a little seems implementing IUrlParameterFormatter is the answer, but I don't have any idea of how to.
Would somebody guide me on this?!

Thanks
Ramin

Most helpful comment

That was my bad. I forgot i switched over to reastease as i needed this same functionality.

All 25 comments

Isn't this: https://github.com/paulcbetts/refit#form-posts what you want?

No, mine is a GET request & the parameters are query string parameters

It shouldn't matter that yours is a GET. If you look at the example it is converted into query string parameters.

So:

public interface IDerpApi
{
    [Get("/durr")]
    Task Herp([Body(BodySerializationMethod.UrlEncoded)] Dictionary<string, object> stuff);
}

var stuff = new Dictionary<string, object> {
    {"herpy", 1}, 
    {"derpy", "bar"}, 
    {"doo", new Guid("d1e9ea6b-2e8b-4699-93e0-0bcbd26c206c")}
};

This should give:

/durr?herpy=1&derpy=bar&doo=d1e9ea6b-2e8b-4699-93e0-0bcbd26c206c

Thank you, I tried that but no success.

What does "no success" mean?

Does it crash? Does it give a malformatted url? something else? Do you want people to guess?

No success means I didn't get the desired result!!
I expected that to narrow the results but it didn't go that way. I also sniffed the request using fiddler & saw that It has body just like it's a post request not the way you said according to documentations.

That dictionary support is really for APIs that take form posts (where the data goes in the request body and the content type is application/x-www-form-urlencoded.

We could possibly extend the querystring parameter generation to work with a dictionary though.

@bennor Well, thank you.
Extending to work with dictionary as #252? Would you please teach me by code or explain it more?

Thanks

Friends, No comment on this? I really don't have any idea.
@bennor @Cheesebaron @ravensorb

Sorry. I'll try to have a look this weekend.

Thanks man that would be appreciated, Hope you get back with good news.

Hey, I've had a quick look into it and I can't see how it's possible without changes. I'll see if I can get a PR together to add support over the next week.

I had a look at #252, but I have no idea what it's about. There's no interface in Refit called IRequestQueryParamSerializer, but a Google search for it brought up RestEase.

Thank you dear,
I also checked what he said but I didn't find the interface, Also emailed to Paul for help on that but no response.
For now I'm not referencing Refit using Nuget, So if you share your changes with me, I can test it well & use it until your PR will available soon.

That was my bad. I forgot i switched over to reastease as i needed this same functionality.

Hi,
@bennor What's the new bro?! Is there any chance?

Completely dropped.off the radar, sorry. Will take a look at it this weekend.

Tnx, I hope you come up with great news 馃槃

Hey @bennor
Did you find any solution on this?!

Not yet. Too much going on in the rest of my life. I should be able commit to having it completed by mid September. Sorry to string you along.

Tnx buddy
Is there any temporary solution for me? Now I made an static method to make the request but I need it to be fixed soon so I can release my app.

If you change control over the API you could change it to accept a form post and use the form body serialization method. Otherwise you'll need to provide static versions of the parameters. Can you make some optional?

I don't have control over the api unfortunately. Also static parameters can't help me, because I have some sort of array in parameters like below:
123=456&123From=4&567To=8
These three parameters are completely dynamic. They can be repetitive & has permutations

Any update when we might see this? I have a similar problem where I cannot control the api. Things get further complicated when its a multipart request with additional form data. I found the api will accept the items as query string parameters but one of the two I need to pass is a dynamic value. A workaround till the Query attribute is available would be helpful if anyone has figured that out?

Hi, any update of this?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

SWarnberg picture SWarnberg  路  4Comments

tstivers1990 picture tstivers1990  路  5Comments

hankovich picture hankovich  路  4Comments

sahinyyurt picture sahinyyurt  路  5Comments

jstafford5380 picture jstafford5380  路  4Comments