(Go: >> BACK << -|- >> HOME <<)

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic querystring! #315

Open
RaminMT opened this issue May 24, 2017 · 25 comments
Open

Dynamic querystring! #315

RaminMT opened this issue May 24, 2017 · 25 comments

Comments

@RaminMT
Copy link
RaminMT commented May 24, 2017

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

@Cheesebaron
Copy link
Contributor

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

@RaminMT
Copy link
Author
RaminMT commented May 24, 2017

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

@Cheesebaron
Copy link
Contributor

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

@Cheesebaron
Copy link
Contributor
Cheesebaron commented May 24, 2017

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

@RaminMT
Copy link
Author
RaminMT commented May 24, 2017

Thank you, I tried that but no success.

@Cheesebaron
Copy link
Contributor
Cheesebaron commented May 24, 2017

What does "no success" mean?

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

@RaminMT
Copy link
Author
RaminMT commented May 24, 2017

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.

@bennor
Copy link
Contributor
bennor commented May 24, 2017

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.

@RaminMT
Copy link
Author
RaminMT commented May 25, 2017

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

Thanks

@RaminMT
Copy link
Author
RaminMT commented May 30, 2017

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

@bennor
Copy link
Contributor
bennor commented Jun 1, 2017

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

@RaminMT
Copy link
Author
RaminMT commented Jun 1, 2017

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

@bennor
Copy link
Contributor
bennor commented Jun 4, 2017

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.

@RaminMT
Copy link
Author
RaminMT commented Jun 4, 2017

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.

@ravensorb
Copy link

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

@RaminMT
Copy link
Author
RaminMT commented Aug 22, 2017

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

@bennor
Copy link
Contributor
bennor commented Aug 22, 2017

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

@RaminMT
Copy link
Author
RaminMT commented Aug 24, 2017

Tnx, I hope you come up with great news 😄

@RaminMT
Copy link
Author
RaminMT commented Aug 30, 2017

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

@bennor
Copy link
Contributor
bennor commented Aug 30, 2017

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.

@RaminMT
Copy link
Author
RaminMT commented Aug 30, 2017

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.

@bennor
Copy link
Contributor
bennor commented Aug 30, 2017

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?

@RaminMT
Copy link
Author
RaminMT commented Aug 31, 2017

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

@napalm684
Copy link

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?

@housecode
Copy link

Hi, any update of this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants