Note that there are some explanatory texts on larger screens.

plurals
  1. POCanonical technique for POSTing an array of objects with REST
    text
    copied!<p>Thank you for taking the time to read this. I looked over Stack Overflow and didn't see a similar question, but if I missed one I apologize.</p> <p>So I'm building a RESTful API, along with a user interface that is the (first) consumer of said REST API.</p> <p>I have a need to create an object. The creation of that object takes a decent amount of configuration.</p> <p>I understand about the verb I need to use (POST - let's not argue this point) and the URL path that I need to have. My question is about how to configure the parameters. Let me give you a sample configuration object in JSON format so as to be agnostic:</p> <pre><code> { name: "foo", barid:1, features:[ { id:1, config: { foo:bar, fubar:baz } }, { id:2, config: { foo:bar, fubar:baz } },... ] } </code></pre> <p>So what I'm wondering is this... what's the correct way to POST the features parameter? Should I just make "features" a JSON string and deserialize it on the server side? Is there some convention that you follow to build an array of nested objects in a RESTful POST? Other developers are going to have to consume this, and I certainly don't want people to have to hand-construct what jQuery did with my JSON object, which looked like:</p> <pre><code>features[0][featureid]:2 features[0][configuration][min]:-64 features[0][configuration][max]:50 features[0][include]:true features[1][featureid]:3 features[1][configuration][min]:0 features[1][configuration][max]:80.5 features[1][include]:true </code></pre> <p>My grails app didn't like that very much :)</p> <p>Thanks again for your time.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload