Creating multiple pages in one REST call
This week a question came up on how to create multiple content-pages with one REST-call in Adobe CQ5.
Of course you first reaction is "great question", but how is that going to work?
The solution is a very nice, very simple one and shows how powerful REST is.
<html>
<body>
<form method="post" action="http://localhost:4502/content/myproject/mycountry/myregion/mycontent">
<input type="hidden" name="../../../jcr:primaryType" value="cq:Page"/>
<input type="hidden" name="../../../jcr:content"/>
<input type="hidden" name="../../../jcr:content/jcr:primaryType" value="cq:PageContent"/>
<input type="hidden" name="../../jcr:primaryType" value="cq:Page"/>
<input type="hidden" name="../../jcr:content"/>
<input type="hidden" name="../../jcr:content/jcr:primaryType" value="cq:PageContent"/>
<input type="hidden" name="../jcr:primaryType" value="cq:Page"/>
<input type="hidden" name="../jcr:content"/>
<input type="hidden" name="../jcr:content/jcr:primaryType" value="cq:PageContent"/>
<input type="hidden" name="./jcr:primaryType" value="cq:Page"/>
<input type="hidden" name="./jcr:content"/>
<input type="hidden" name="./jcr:content/jcr:primaryType" value="cq:PageContent"/>
<input type="submit"/>
</form>
</body>
</html>
The form as shown above about will create the complete path to "/content/myproject/mycountry/myregion/mycontent", so that will mean four pages "myproject", "mycountry", "myregion", "mycontent".
With the ../ notation you can refer to the correct level and specify properties you want to assign
To test this in your local CQ5-instance you create a .html file and copy the content from the form into the file. Open the file in a browser and hit the 'Submit' button.
POST /content
myproject/jcr:primaryType=cq:Page
myproject/mycountry/jcr:primaryType=cq:Page
myproject/mycountry/myregion/jcr:primaryType=cq:Page
myproject/mycountry/myregion/mycontent/jcr:primaryType=cq:Page
Might be a bit more intuitive.
The post servlet will create any missing (intermediary) node, regardless of whether it is part of the request resource or of any parameters pointing to a property.