<
From version < 77.1 >
edited by slauriere
on 2019/01/24
To version < 78.1 >
edited by Vincent Massol
on 2019/01/24
>
Change comment: There is no comment for this version

Summary

Details

Page properties
Author
... ... @@ -1,1 +1,1 @@
1 -XWiki.slauriere
1 +XWiki.VincentMassol
Content
... ... @@ -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"}}

Get Connected