Giter VIP home page Giter VIP logo

Comments (4)

weavejester avatar weavejester commented on July 22, 2024

You don't seem to be applying the wrap-nested-params middleware. Nested parameters are not something inherent to HTTP; they're simply a convention adopted by certain frameworks. In Ring you have the option of using this syntax via the wrap-nested-params middleware.

However, the desired result you want won't work with the input you provide, whether in Ring:

user=> (nested-params-request {:params {"contraints[0][]" ["A" "B"], "want" "C"}})
{:params {"want" "C", "contraints" {"0" ["A" "B"]}}}

Or in Rails:

irb> Rack::Utils.parse_nested_query("constraints[0][]=A&constraints[0][]=B&want=C")
=> {"constraints"=>{"0"=>["A", "B"]}, "want"=>"C"}

from ring.

eigenhombre avatar eigenhombre commented on July 22, 2024

@weavejester Is the conversion of {constraints: [["A", "B"]]} into {"constraints[0][]" ["A" "B"]} done on the jQuery side, or the Ring side? Because nested arrays serialize just fine into JSON in general:

>  python
Python 2.6.8 (unknown, Nov 17 2012, 21:23:35) 
>>> import json
>>> json.dumps({"want": "C", "constraints": [["A","B"]]})
'{"want": "C", "constraints": [["A", "B"]]}'

@mrocklin You don't state in the ticket if this gives the same result with a POST as it does with GET. Does it? Because GETs have to stuff their parameters into the HTTP URL arguments, I can understand why this would go sideways -- but maybe POSTs are more robust (since you can just pass data, unmunged...?).

I guess I'm confused exactly where this simple thing is breaking down. And, what people usually do about it. Thanks!

from ring.

mrocklin avatar mrocklin commented on July 22, 2024

Post does better because it does actually decode the query-string and push the result into the :params key (EDIT: this is probably because I started wrapping my routes with compojure.handler/api). However it also fails to a nested array. I suspect that this still depends on form-decode.

$.post("/query/", {want: "C", constraints: [["A", "B"]]},
    function(data, aStatus, dummy){
        alert(data);
    });
{:scheme :http,
 :query-params {},
 :form-params {"constraints[0][]" ["A" "B"], "want" "C"},
 :request-method :post,
 :query-string nil,
 :params {:want "C", :constraints {"0" ["A" "B"]}},
 :body #<HttpInput org.eclipse.jetty.server.HttpInput@16535bf>}

From what @weavejester writes it seems that my issue is really what I should expect from any system. It seems like the best path may be to kludge together a local array-from-map function.

from ring.

weavejester avatar weavejester commented on July 22, 2024

@weavejester Is the conversion of {constraints: [["A", "B"]]} into {"constraints[0][]" ["A" "B"]} done on the jQuery side, or the Ring side?

On the jQuery side, since that's where the request is coming from.

From what @weavejester writes it seems that my issue is really what I should expect from any system. It seems like the best path may be to kludge together a local array-from-map function.

Or just use JSON, instead of trying to encode a data structure in form parameters, which aren't really designed for that.

from ring.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.