2

Brief

I'm trying to call some API endpoints who use nested query strings in the GET calls

Issue

Trying not to reinvent the wheel, I'm looking for a library that is able to convert a nested object into query string parameters

Example

Given the object:

{'searchCriteria':{'filterGroups':[{'filters':[{'field':'entity_id','value':"1",'condition_type':'eq'}]}]}}

Results into a URL on the likes of: http://example.com/rest/V1/products?searchCriteria[filterGroups][0][filters][0][field]=entity_id&searchCriteria[filterGroups][0][filters][0][condition_type]=eq&searchCriteria[filterGroups][0][filters][0][value]=5325

or, when expanded:

searchCriteria[filterGroups][0][filters][0][field]=entity_id
searchCriteria[filterGroups][0][filters][0][condition_type]=eq
searchCriteria[filterGroups][0][filters][0][value]=5325

Resources

Equivalent nodejs library: https://www.npmjs.com/package/qs

Recap

How do you serialise/deserialise a nested query string?

5
  • Does this answer your question? Convert JSON data to querystring in C# GET request Commented Sep 23, 2020 at 13:41
  • @YegorAndrosov not exactly. that's only going one level deep and it's not generic Commented Sep 23, 2020 at 13:52
  • this article looks like what you need geeklearning.io/… Commented Sep 23, 2020 at 14:43
  • I can say that Flurl doesn't do this out of the box, and I think it'll be hard to find something that does because AFAIK there's no widely agreed upon best practice for stringifying a nested object in a query string. I'd even argue it's poor API design, but I'm guessing you have no control over that. Commented Sep 23, 2020 at 16:15
  • @ToddMenier it's the first time I come across something like this and I agree it's not pretty - it's the old api for magento. I'll probably look into the graphql api instead, luckily it does have support for it. Commented Sep 23, 2020 at 17:16

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.