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?

ioan
  • 751
  • 1
  • 9
  • 26
  • Does this answer your question? [Convert JSON data to querystring in C# GET request](https://stackoverflow.com/questions/12610585/convert-json-data-to-querystring-in-c-sharp-get-request) – Yehor Androsov Sep 23 '20 at 13:41
  • @YegorAndrosov not exactly. that's only going one level deep and it's not generic – ioan Sep 23 '20 at 13:52
  • this article looks like what you need https://geeklearning.io/serialize-an-object-to-an-url-encoded-string-in-csharp/ – Yehor Androsov Sep 23 '20 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. – Todd Menier Sep 23 '20 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. – ioan Sep 23 '20 at 17:16

0 Answers0