Change comment:
There is no comment for this version
Summary
-
Page properties (2 modified, 0 added, 0 removed)
Details
- Page properties
-
- Author
-
... ... @@ -1,1 +1,1 @@ 1 -XWiki. mslw1 +XWiki.VincentMassol - Content
-
... ... @@ -297,7 +297,7 @@ 297 297 * **HTTP Method:** GET 298 298 ** **Media types:** 299 299 *** application/xml (SearchResults element) 300 -** **Description:** Allow to execute HQL, XWQL, Lucene or SOLR queries on the given {wikiName}. The //q// parameter contains the corresponding query. See [[HQL Query Examples in Velocity>>platform:DevGuide.velocityHqlExamples]], [[XWiki Query Language Specification>>dev:Design.XWiki Query Language Specification]], [[Lucene Plugin>>extensions:Extension.Lucene Plugin]] and [[SOLR query API>>extensions:Extension.Solr Search Query API]] examples of the queries that can be specified in this parameter. If type is //hql// and //className// is specified, the result will also contain the data for the first object of the corresponding class. 300 +** **Description:** Allow to execute HQL, XWQL, Lucene or SOLR queries on the given {wikiName}. The //q// parameter contains the corresponding query. See [[HQL Query Examples in Velocity>>platform:DevGuide.velocityHqlExamples]], [[XWiki Query Language Specification>>dev:Design.XWiki Query Language Specification]], [[Lucene Plugin>>extensions:Extension.Lucene Plugin]] and [[SOLR query API>>extensions:Extension.Solr Search Query API]] examples of the queries that can be specified in this parameter. If type is //hql// or //xwql// and //className// is specified, the result will also contain the data for the first object of the corresponding class. 301 301 ** **Status codes:** 302 302 *** 200: If the request was successful. 303 303 ... ... @@ -1003,6 +1003,45 @@ 1003 1003 1004 1004 = Custom resources = 1005 1005 1006 +== In Wiki Pages == 1007 + 1008 +If you can't find an existing REST endpoint for your needs, you can create your own own by creating a wiki page and putting script in it. For example let's imagine you'd like to get a list of all pages under a given space. You could write a page, say ##GetChildren## with the following content: 1009 + 1010 +{{code language="velocity"}} 1011 +{{velocity}} 1012 +#if ("$!request.space" != '') 1013 + #set ($discard = $response.setContentType('text/xml')) 1014 + <?xml version="1.0" encoding="UTF-8"?> 1015 + <pages> 1016 + #set ($query = $services.query.xwql("select doc.fullName from Document doc where ((doc.space like :spacelike escape '!') or (doc.space = :space)) and language='' order by doc.date desc")) 1017 + #set ($spaceReferenceString = $request.space) 1018 + #set ($spaceLike = $spaceReferenceString.replaceAll('([%_!])', '!$1').concat('.%')) 1019 + #set ($query = $query.bindValue('spacelike', $spaceLike)) 1020 + #set ($query = $query.bindValue('space', $spaceReferenceString)) 1021 + #foreach ($item in $query.execute()) 1022 + <page>$item</page> 1023 + #end 1024 + </pages> 1025 +#end 1026 +{{/velocity}} 1027 +{{/code}} 1028 + 1029 +The calling it for example with the following URL ##http:~/~/localhost:8080/xwiki/bin/get/GetChildren/?space=Sandbox&xpage=plain&outputSyntax=plain## would give something like: 1030 + 1031 +{{code language="none"}} 1032 +<pages> 1033 +<page>Sandbox.Test.WebHome</page> 1034 +<page>Sandbox.TestPage2</page> 1035 +<page>Sandbox.ApplicationsPanelEntry</page> 1036 +<page>Sandbox.TestPage3</page> 1037 +<page>Sandbox.TestPage1</page> 1038 +<page>Sandbox.WebPreferences</page> 1039 +<page>Sandbox.WebHome</page> 1040 +</pages> 1041 +{{/code}} 1042 + 1043 +== In Java == 1044 + 1006 1006 It's possible to easily add any REST resource by registering a ##org.xwiki.rest.XWikiResource## java component on your wiki (see [[Component guide>>platform:DevGuide.WritingComponents]] for more details). 1007 1007 1008 1008 {{code language="java"}}