Wiki source code of The XWiki RESTful API

Version 32.1 by Fabio Mancinelli on 2011/10/20

Show last authors
1 {{box cssClass="floatinginfobox" title="**Contents**"}}
2 {{toc depth="2"/}}
3 {{/box}}
4
5 XWiki provides fine-grain access to virtually every element through an API that is based on HTTP semantics, i.e., a RESTful API. In this page you will find all the details to take advantage of this API and the instructions to use it at its full potential.
6
7 See also this [[tutorial by Fabio Mancinelli>>http://blog.fabiomancinelli.org/2011/03/07/XWikis_RESTful_API.html]].
8
9 = Accessing the service =
10
11 By defaut the XWiki RESTful API entrypoint is rooted at the following URI:
12
13 {{code}}
14
15 http://host:port/xwiki/rest
16
17 {{/code}}
18
19 All the resource references described in the [[XWiki RESTful API Documentation>>#HXWikiRESTfulAPIDocumentation]] should be intended relative to this URL.
20
21 For example the ##/wikis## resources on a server running on ##localhost## on port ##8080## can be retrieved using the following URL : ##http:~/~/localhost:8080/xwiki/rest/wikis##
22
23 In addition to retrieving content in XML format, you can also retrieve it in JSON format by adding the parameter ##?media=json## in the URL. For example: ##http:~/~/localhost:8080/xwiki/rest/wikis?media=json##
24
25 = Dataset =
26
27 This section contains a brief and high-level description of the XWiki data set that should serve as a basis for presenting resources and their associated operations.
28
29 XWiki has **pages** organized in **spaces**. Each **page** is available in multiple **versions** (its **history**) and **translations**. Translated pages have their own **versions** and **history** which are independent. Each page might have **attachments**. Each attachment has its own **history**. Attachments are shared among all the different translations of a page (i.e., the same set of attachments is the same regardless of the page language). Pages can have one or more **objects**. Objects are instances of a **class** that contains a set of **properties**. Some objects might be directly exposed as first class entities, such as **comments** and **tags**. Objects, as attachments, are shared among all page translations.
30
31 = Understanding resources and representations =
32
33 "An important concept in REST is the existence of resources (sources of specific information), each of which is referenced with a global identifier (e.g., an URI in HTTP). In order to manipulate these resources, components of the network (user agents and origin servers) communicate via a standardized interface (e.g., HTTP) and exchange representations of these resources (the actual documents conveying the information)." ([[Wikipedia>>http://en.wikipedia.org/wiki/Representational_State_Transfer#REST.27s_central_principle:_resources]])
34
35 Resources in XWiki are pages, attachments, objects, properties, spaces, and all the //things// we described in the previous section. XWiki has a default way of conveying the information about these resources, i.e., by providing well defined XML representations that contain all the information associated to the resource in an XML format. This format is described using an XML Schema Definition file that can be found here: [[https://github.com/xwiki/xwiki-platform/blob/master/xwiki-platform-core/xwiki-platform-rest/xwiki-platform-rest-model/src/main/resources/xwiki.rest.model.xsd]]
36
37 Of course the same resource can be represented in many different ways. This is yet to be documented.
38
39 Another important aspect of representations is that they contain useful information for linking related resources. This is a realization of the //Hypermedia As The Engine Of The Application State (HATEOAS)// principle. In XML representations this information is conveyed through the ##<link>## tag. This tag has two important parameters: **rel** and **href**. **rel** specifies the "semantics" of the link, while **href** is the URI of the linked resource.
40
41 For example, in the representation of a page, we can have links to the comments, tags, attachments which are independent resources associated to the current page. These links are provided in the XML representation of a page and allow a client to navigate to related resources... Like we do every day when we click on a link in a web page.
42
43 [[image:representation||height="430"]]
44
45 == Relations ==
46
47 The available relations that you might find in the XML resource representations are the following:
48
49 |=Rel|=Semantics
50 |{{{http://www.xwiki.org/rel/wikis}}}|The representation containing the list of virtual wikis.
51 |{{{http://www.xwiki.org/rel/spaces}}}|The representation containing the list of spaces in a wiki.
52 |{{{http://www.xwiki.org/rel/pages}}}|The representation containing the list of pages in a space.
53 |{{{http://www.xwiki.org/rel/translation}}}|The representation containing a translation of a page.
54 |{{{http://www.xwiki.org/rel/page}}}|The representation for a page.
55 |{{{http://www.xwiki.org/rel/space}}}|The representation for a space.
56 |{{{http://www.xwiki.org/rel/parent}}}|The representation for the page that is parent of the current resource.
57 |{{{http://www.xwiki.org/rel/home}}}|The representation for the page that is the home of the current resource.
58 |{{{http://www.xwiki.org/rel/attachmentData}}}|The representation of the actual attachment data.
59 |{{{http://www.xwiki.org/rel/comments}}}|The representation of the list of comments associated to the current resource.
60 |{{{http://www.xwiki.org/rel/attachments}}}|The representation of the list of attachments associated to the current resource.
61 |{{{http://www.xwiki.org/rel/objects}}}|The representation of the list of objects associated to the current resource.
62 |{{{http://www.xwiki.org/rel/object}}}|The representation for an object.
63 |{{{http://www.xwiki.org/rel/classes}}}|The representation of the list of classes associated to the current resource.
64 |{{{http://www.xwiki.org/rel/history}}}|The representation of the list of history information associated to the current resource.
65 |{{{http://www.xwiki.org/rel/class}}}|The representation for a class.
66 |{{{http://www.xwiki.org/rel/property}}}|The representation for a property.
67 |{{{http://www.xwiki.org/rel/properties}}}|The representation of the list of properties associated to the current resource.
68 |{{{http://www.xwiki.org/rel/modifications}}}|The representation of the list of modifications associated to the current resource.
69 |{{{http://www.xwiki.org/rel/children}}}|The representation of the list of children associated to the current resource.
70 |{{{http://www.xwiki.org/rel/tags}}}|The representation of the list of tags associated to the current resource.
71 |{{{http://www.xwiki.org/rel/tag}}}|The representation of a tag.
72 |{{{http://www.xwiki.org/rel/search}}}|The representation for a search resource.
73 |{{{http://www.xwiki.org/rel/syntaxes}}}|The representation for a syntax resource.
74
75 Relations are defined as URIs in order to provide a sort of namespace. Currently these URIs are not links to real web pages but, in the future, they might point to descriptions of their semantics on actual web pages (or other kinds of representations).
76
77 == The "HATEOAS" Graph ==
78
79 In order to better understand the relations among resources you might have a look at this [[graph>>attach:XWikiHATEOAS.pdf]] that pictures all the resources available in the XWiki RESTful API and the relations among them. In this graph, nodes are [[URI templates>>http://bitworking.org/projects/URI-Templates/spec/draft-gregorio-uritemplate-03.txt]] representing classes of resources. Edges are the possible links that you might find in a representation of a given resource, and their associated relations.
80
81 This graph shows that by starting from the API entry-point a client can navigate and discover all the resources just by following the links provided in representations (and by knowing their semantics). This was exactly the way how this graph was generated.
82
83 = Interacting with the XWiki RESTful API =
84
85 The XWiki RESTful API is accessible through HTTP so, in principle, you can use every client that is capable of "speaking" HTTP in order to interact with it. Even a web browser!
86 If you want to write more complex programs you might download an HTTP library for your favorite language (e.g., [[http://hc.apache.org/]]).
87
88 Java users might take advantage of the [[JAXB>>https://jaxb.dev.java.net]] framework and its [[XJC binding compiler>>https://jaxb.dev.java.net/jaxb20-ea3/docs/xjc.html]] in order to generate domain object models directly from the [[XML Schema Definition>>https://github.com/xwiki/xwiki-platform/blob/master/xwiki-platform-core/xwiki-platform-rest/xwiki-platform-rest-model/src/main/resources/xwiki.rest.model.xsd]], and use them for serializing and de-serializing XML representations.
89
90 If you use this approach (Apache HTTP Client + JAXB) you will find yourself writing some code like this:
91
92 {{code language="java"}}
93 import javax.xml.bind.JAXBContext;
94 import javax.xml.bind.Unmarshaller;
95
96 import org.apache.commons.httpclient.HttpClient;
97 import org.apache.commons.httpclient.methods.GetMethod;
98 import org.xwiki.rest.model.jaxb.Page;
99
100 ...
101 HttpClient httpClient = new HttpClient();
102 JAXBContext context = JAXBContext.newInstance("org.xwiki.rest.model.jaxb");
103 Unmarshaller unmarshaller = context.createUnmarshaller();
104
105 GetMethod getMethod = new GetMethod("http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/Main/pages/WebHome");
106 getMethod.addRequestHeader("Accept", "application/xml");
107 httpClient.executeMethod(getMethod);
108
109 Page page = (Page) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
110 {{/code}}
111
112 And you will have all the information about the Main.WebHome page in the Page object, without the need of handling XML directly.
113
114 Because of the wide variety of HTTP frameworks available we don't provide a full tutorial about using them. However, in order to show you how to interact with the XWiki RESTful API, we will use [[curl>>http://curl.haxx.se]]: a standard command line HTTP client that provides an interface to all the functionalities of the HTTP protocol.
115
116 By using curl, the previous example would have been:
117
118 {{code language="xml"}}
119 $ curl http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/Main/pages/WebHome
120 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
121 <page xmlns="http://www.xwiki.org">
122 <link rel="http://www.xwiki.org/rel/space" href="http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/Main"/>
123 ...
124 {{/code}}
125
126 == Authentication ==
127
128 The XWiki RESTful API supports two types of authentication:
129
130 * **HTTP BASIC Auth**: You provide your credentials using the Authorization HTTP header
131 * **XWiki session**: If you are logged in XWiki and you use the cookies provided by the authentication mechanism, you will also be authenticated to the XWiki RESTful API. This is useful, for example, when you are interacting with the API using the XMLHttpRequest object of a browser using Javascript.
132
133 If you don't provide any credentials the XWiki RESTful API will recognize you as a XWiki.Guest user.
134
135 So if you have, let's say a Main.PrivatePage, and you try to do:
136
137 {{code language="none"}}
138 $ curl -v http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/Main/pages/PrivatePage
139 ...
140 < HTTP/1.1 401 Unauthorized
141 ...
142 {{/code}}
143
144 You will get an Unauthorized empty response.
145
146 On the contrary, by specifying Admin credentials you gain access to the actual page:
147
148 {{code language="xml"}}
149 $ curl -u Admin:admin http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/Main/pages/PrivatePage
150 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
151 <page xmlns="http://www.xwiki.org">
152 <link rel="http://www.xwiki.org/rel/space" href="http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/Main"/>
153 ...
154 <content>Only admin can see this</content>
155 </page>
156 {{/code}}
157
158 == Sending representations ==
159
160 Many resources are modifiable, so you can send representations in order to change the state of those resources (e.g., pages).
161 All modifiable resources accept XML representations that conform to the [[XML Schema Definition>>https://github.com/xwiki/xwiki-platform/blob/master/xwiki-platform-core/xwiki-platform-rest/xwiki-platform-rest-model/src/main/resources/xwiki.rest.model.xsd]]. However, some other representations might be accepted as well (see the following sections).
162
163 Resource update is usually done by using the PUT method, while resource creation is done via PUT or POST.
164
165 For example, in order to create a page you might do the following:
166
167 {{code language="xml"}}
168 $ curl -u Admin:admin -X PUT --data-binary "@newpage.xml" -H "Content-Type: application/xml" http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/Main/pages/NewPage
169 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
170 <page xmlns="http://www.xwiki.org">
171 <link rel="http://www.xwiki.org/rel/space" href="http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/Main"/>
172 ...
173 <version>1.1</version>
174 <majorVersion>1</majorVersion>
175 <minorVersion>1</minorVersion>
176 <created>2009-03-21+01:00</created>
177 <creator>XWiki.Admin</creator>
178 <modified>2009-03-21+01:00</modified>
179 <modifier>XWiki.Admin</modifier>
180 <content>This is a new page</content>
181 </page>
182 {{/code}}
183
184 Where newpage.xml is an XML file containing
185
186 {{code language="xml"}}
187 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
188 <page xmlns="http://www.xwiki.org">
189 <title>Hello world</title>
190 <syntax>xwiki/2.0</syntax>
191 <content>This is a new page</content>
192 </page>
193 {{/code}}
194
195 The page has been created and is accessible. Subsequent PUT requests to the page URI will modify its content.
196
197 You can specify a subset of the three elements {{{title}}}, {{{syntax}}}, and {{{content}}} in the XML when updating/creating a page.
198 For example, if you just want to change the title, it is sufficient to specify only the {{{title}}} element. The current content and the syntax of the page will be left unchanged.
199
200 == Overcoming browser limitations ==
201
202 As said before, it could be useful to send information by using browser's XmlHttpRequest objects. However, currently many browsers only support GET and POST methods, so it is impossible to send, for example, PUT requests. In order to overcome this limitation you can override the HTTP Method by specifying a ##method## parameter in the URI query string.
203
204 In the previous example, if you send a POST request to the ##[[http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/Main/pages/NewPage?method=PUT]]## it will be interpreted as if it were an actual PUT request.
205
206 This overriding mechanism allows the interaction with the XWiki RESTful API by using any kind of browser.
207
208 == PUT vs POST ==
209
210 In the following sections you will see that sometimes resources are created by using PUT and sometimes by using POST. The general principle is that if the client is responsible for choosing the resource URI then PUT is used. If it's the server that bears this responsibility, then POST is used.
211
212 To be clearer, when a client wants to create a page it knows **where** that page should go, so it is able to communicate the server the target URI. PUT is used.
213
214 A client, on the contrary, cannot know beforehand what will be the URI of a comment, since comment URIs contains the ID of the comment and this information is generated by the server. In this case the client will do a POST and the server, in response, will communicate the URI it generated for the newly created comment.
215
216 = XWiki RESTful API Documentation =
217
218 In this section you will find the documentation of the whole XWiki RESTful API.
219
220 **application/xml** representations refers to the XML Schema Definition at the following location: [[https://github.com/xwiki/xwiki-platform/blob/master/xwiki-platform-core/xwiki-platform-rest/xwiki-platform-rest-model/src/main/resources/xwiki.rest.model.xsd]]
221
222 Resource URIs are specified using [[URI templates>>http://bitworking.org/projects/URI-Templates/spec/draft-gregorio-uritemplate-03.txt]]. Bracketed elements are formal parameters and should be instantiated to actual values in order to retrieve the associated resource.
223
224 == Root resources ==
225
226 By defaut all the resources of the RESTful API are rooted at the following URI: ##http:~/~/server:port/xwiki/rest/## (depending on where your XWiki is running)
227
228 === / ===
229
230 * **HTTP Method:** GET
231 ** **Media types:**
232 *** application/xml (XWiki element)
233 ** **Description:** Retrieves the entry root description containing information about the server.
234 ** **Status codes:**
235 *** 200: If the request was successful.
236
237 === /syntaxes
238
239 * **HTTP Method:** GET
240 ** **Media types:**
241 *** application/xml (Syntaxes element)
242 ** **Description:** The list of syntaxes supported by the XWiki instance.
243 ** **Status codes:**
244 *** 200: If the request was successful.
245
246 === /wikis ===
247
248 * **HTTP Method:** GET
249 ** **Media types:**
250 *** application/xml (Wikis element)
251 ** **Description:** The list of wikis available on the XWiki instance. Unless the wiki is configured to be a wiki farm, this list is usually made of a single element 'xwiki'.
252 ** **Status codes:**
253 *** 200: If the request was successful.
254
255 === /wikis/{wikiName}/search?q~={keywords}~[~[&scope~={name,content,title,objects}...]&number~=n] ===
256
257 * **HTTP Method:** GET
258 ** **Media types:**
259 *** application/xml (SearchResults element)
260 ** **Description:** The list of pages and objects that contain the {keywords} in the specified {scope}s. Multiple scopes can be specified. Search results are relative to the whole {wikiName}
261 ** **Status codes:**
262 *** 200: If the request was successful.
263
264 == Space resources ==
265
266 === /wikis/{wikiName}/spaces[?start~=offset&number~=n] ===
267
268 * **HTTP Method:** GET
269 ** **Media types:**
270 *** application/xml (Spaces element)
271 ** **Description:** Retrieves the list of spaces available in the {wikiName} wiki.
272 ** **Status codes:**
273 *** 200: If the request was successful.
274
275 === /wikis/{wikiName}/spaces/{spaceName}/search?q~={keywords}~[~[&scope~={name,content,title,objects}...]&number~=n] ===
276
277 * **HTTP Method:** GET
278 ** **Media types:**
279 *** application/xml (Search results element)
280 ** **Description:** The list of pages and objects that contain the {keywords} in the specified {scope}s. Multiple scopes can be specified. Search results are relative to space {spaceName}
281 ** **Status codes:**
282 *** 200: If the request was successful.
283 *** 401: If the user is not authorized.
284
285 == Page resources ==
286
287 === /wikis/{wikiName}/spaces/{spaceName}/pages[?start~=offset&number~=n] ===
288
289 * **HTTP Method:** GET
290 ** **Media types:**
291 *** application/xml (Pages element)
292 ** **Description:** The list of pages in the space {spaceName}
293 ** **Status codes:**
294 *** 200: If the request was successful.
295 *** 401: If the user is not authorized.
296
297 === /wikis/{wikiName}/spaces/{spaceName}/pages/{pageName} ===
298
299 * **HTTP Method:** GET
300 ** **Media types:**
301 *** application/xml (Page element)
302 ** **Description:**
303 ** **Status codes:**
304 *** 200: If the request was successful.
305 *** 401: If the user is not authorized.
306
307 \\
308
309 * **HTTP Method:** PUT
310 ** **Accepted Media types:**
311 *** application/xml (Page element)
312 *** text/plain (Only page content)
313 *** application/x-www-form-urlencoded (allowed field names: title, parent, content)
314 ** **Media types:**
315 *** application/xml (Page element)
316 ** **Description:** Create or updates a page.
317 ** **Status codes:**
318 *** 201: If the page was created.
319 *** 202: If the page was updated.
320 *** 304: If the page was not modified.
321 *** 401: If the user is not authorized.
322
323 \\
324
325 * **HTTP Method:** DELETE
326 ** **Media types:**
327 *** application/xml (Page element)
328 ** **Description:** Delete the page.
329 ** **Status codes:**
330 *** 204: If the request was successful.
331 *** 401: If the user is not authorized.
332
333 === /wikis/{wikiName}/spaces/{spaceName}/pages/{pageName}/history[?start~=offset&number~=n] ===
334
335 * **HTTP Method:** GET
336 ** **Media types:**
337 *** application/xml (History element)
338 ** **Description:** The list of all the versions of the given page.
339 ** **Status codes:**
340 *** 200: If the request was successful.
341 *** 401: If the user is not authorized.
342
343 === /wikis/{wikiName}/spaces/{spaceName}/pages/{pageName}/history/{version} ===
344
345 * **HTTP Method:** GET
346 ** **Media types:**
347 *** application/xml (Page element)
348 ** **Description:** The page at version {version}
349 ** **Status codes:**
350 *** 200: If the request was successful.
351 *** 401: If the user is not authorized.
352
353 ==== /wikis/{wikiName}/spaces/{spaceName}/pages/{pageName}/translations[?start~=offset&number~=n] ====
354
355 * **HTTP Method:** GET
356 ** **Media types:**
357 *** application/xml (Translations element)
358 ** **Description:** The list of available translation for the page
359 ** **Status codes:**
360 *** 200: If the request was successful.
361 *** 401: If the user is not authorized.
362
363 === /wikis/{wikiName}/spaces/{spaceName}/pages/{pageName}/translations/{language} ===
364
365 * **HTTP Method:** GET
366 ** **Media types:**
367 *** application/xml (Page element)
368 ** **Description:** The page at in the given {language}.
369 ** **Status codes:**
370 *** 200: If the request was successful.
371 *** 401: If the user is not authorized.
372
373 \\
374
375 * **HTTP Method:** PUT
376 ** **Accepted Media types:**
377 *** application/xml (Page element)
378 *** text/plain (Only page content)
379 *** application/x-www-form-urlencoded (allowed field names: title, parent, content)
380 ** **Media types:**
381 *** application/xml (Page element)
382 ** **Description:** Create or updates a page translation.
383 ** **Status codes:**
384 *** 201: If the page was created.
385 *** 202: If the page was updated.
386 *** 304: If the page was not modified.
387 *** 401: If the user is not authorized.
388
389 \\
390
391 * **HTTP Method:** DELETE
392 ** **Media types:**
393 *** application/xml (Page element)
394 ** **Description:** Delete the page translation.
395 ** **Status codes:**
396 *** 204: If the request was successful.
397 *** 401: If the user is not authorized.
398
399 === /wikis/{wikiName}/spaces/{spaceName}/pages/{pageName}/translations/{language}/history ===
400
401 * **HTTP Method:** GET
402 ** **Media types:**
403 *** application/xml (History element)
404 ** **Description:** The list of all the available revisions of the page in a given {language}.
405 ** **Status codes:**
406 *** 200: If the request was successful.
407 *** 401: If the user is not authorized.
408
409 === /wikis/{wikiName}/spaces/{spaceName}/pages/{pageName}/translations/{lang}/history/{version} ===
410
411 * **HTTP Method:** GET
412 ** **Media types:**
413 *** application/xml (Page element)
414 ** **Description:** A page at a given {version} in a given {language}.
415 ** **Status codes:**
416 *** 200: If the request was successful.
417 *** 401: If the user is not authorized.
418
419 === /wikis/{wikiName}/spaces/{spaceName}/pages/{pageName}/children ===
420
421 * **HTTP Method:** GET
422 ** **Media types:**
423 *** application/xml (Pages element)
424 ** **Description:** The list of the children of a given page.
425 ** **Status codes:**
426 *** 200: If the request was successful.
427 *** 401: If the user is not authorized.
428
429 === /wikis/{wikiName}/pages[?name~=paneName&space~=spaceName&author~=authorName] ===
430
431 * **HTTP Method:** GET
432 ** **Media types:**
433 *** application/xml (Pages element)
434 ** **Description:** The list of pages in the wiki {wikiName}. Filters can be set for the name, space and/or author to include only pages that match the given filters. This resource can be used to search for pages in a wiki.
435 ** **Status codes:**
436 *** 200: If the request was successful.
437 *** 401: If the user is not authorized.
438
439 == Tag resources ==
440
441 === /wikis/{wikiName}/spaces/{spaceName}/pages/{pageName}/tags ===
442
443 * **HTTP Method:** GET
444 ** **Media types:**
445 *** application/xml (Tags element)
446 ** **Description:** List page tags.
447 ** **Status codes:**
448 *** 200: If the request was successful.
449 *** 401: If the user is not authorized.
450
451 \\
452
453 * **HTTP Method:** PUT
454 ** **Accepted Media types:**
455 *** application/xml (Tag element)
456 *** text/plain
457 *** application/x-www-form-urlencoded (allowed field names: tag)
458 ** **Media types:**
459 *** application/xml (Tags element)
460 ** **Description:** Add a tag to the page.
461 ** **Status codes:**
462 *** 202: If the request was successful.
463 *** 401: If the user is not authorized.
464
465 === /wikis/{wikiName}/tags ===
466
467 * **HTTP Method:** GET
468 ** **Media types:**
469 *** application/xml (Tags element)
470 ** **Description:** The list of all available tags
471 ** **Status codes:**
472 *** 200: If the request was successful.
473 *** 401: If the user is not authorized.
474
475 === /wikis/{wikiName}/tags/{tag1}[,{tag2},{tag3}...][?start~=offset&number~=n] ===
476
477 * **HTTP Method:** GET
478 ** **Media types:**
479 *** application/xml (Pages element)
480 ** **Description:** The list of pages having the specified tags.
481 ** **Status codes:**
482 *** 200: If the request was successful.
483 *** 401: If the user is not authorized.
484
485 == Comments resources ==
486
487 === /wikis/{wikiName}/spaces/{spaceName}/pages/{pageName}/comments[?start~=offset&number~=n] ===
488
489 * **HTTP Method:** GET
490 ** **Media types:**
491 *** application/xml (Comments element)
492 ** **Description:** The list of comments on a given page.
493 ** **Status codes:**
494 *** 200: If the request was successful.
495 *** 401: If the user is not authorized.
496
497 \\
498
499 * **HTTP Method:** POST
500 ** **Accepted Media types:**
501 *** application/xml (Comment element)
502 *** text/plain
503 *** application/x-www-form-urlencoded - allowed field names: ##text##, ##replyTo## (object number of the replied comment, since XE 2.3)
504 ** **Media types:**
505 *** application/xml (Comment element)
506 ** **Description:** Create a comment on the given page.
507 ** **Status codes:**
508 *** 201: If the comment was created. (The Location header will contain the URI where the comment has been created.)
509 *** 401: If the user is not authorized.
510
511 === /wikis/{wikiName}/spaces/{spaceName}/pages/{pageName}/comments/{commentId} ===
512
513 * **HTTP Method:** GET
514 ** **Media types:**
515 *** application/xml (Comment element)
516 ** **Description:** A specific comment on a page
517 ** **Status codes:**
518 *** 200: If the request was successful.
519 *** 401: If the user is not authorized.
520
521 === /wikis/{wikiName}/spaces/{spaceName}/pages/{pageName}/history/{version}/comments ===
522
523 * **HTTP Method:** GET
524 ** **Media types:**
525 *** application/xml (Comments element)
526 ** **Description:** The list of comments at a specific page {version}.
527 ** **Status codes:**
528 *** 200: If the request was successful.
529 *** 401: If the user is not authorized.
530
531 === /wikis/{wikiName}/spaces/{spaceName}/pages/{pageName}/history/{version}/comments/{commentId} ===
532
533 * **HTTP Method:** GET
534 ** **Media types:**
535 *** application/xml (Comment element)
536 ** **Description:** A comment at a specific page {version}.
537 ** **Status codes:**
538 *** 200: If the request was successful.
539 *** 401: If the user is not authorized.
540
541 == Attachments resources ==
542
543 === /wikis/{wikiName}/spaces/{spaceName}/pages/{pageName}/attachments[?start~=offset&number~=n] ===
544
545 * **HTTP Method:** GET
546 ** **Media types:**
547 *** application/xml (Attachments element)
548 ** **Description:** The list of attachments of a given page.
549 ** **Status codes:**
550 *** 200: If the request was successful.
551 *** 401: If the user is not authorized.
552
553 === /wikis/{wikiName}/spaces/{spaceName}/pages/{pageName}/attachments/{attachmentName} ===
554
555 * **HTTP Method:** GET
556 ** **Media types:**
557 *** The same of the attachment media type.
558 ** **Description:** The attachment identified by {attachmentName} on a given page.
559 ** **Status codes:**
560 *** 200: If the request was successful.
561 *** 401: If the user is not authorized.
562
563 \\
564
565 * **HTTP Method:** PUT
566 ** **Accepted media types:**
567 *** **/**
568 ** **Media types:**
569 *** application/xml (AttachmentSummary element)
570 ** **Description:** Create an attachment identified by {attachmentName} on a given page.
571 ** **Status codes:**
572 *** 201: If the attachment was created.
573 *** 202: If the attachment was updated.
574 *** 401: If the user is not authorized.
575
576 \\
577
578 * **HTTP Method:** DELETE
579 ** **Media types:**
580 ** **Description:** Delete the attachment identified by {attachmentName} on a given page.
581 ** **Status codes:**
582 *** 204: If the attachment was deleted.
583 *** 401: If the user is not authorized.
584
585 === /wikis/{wikiName}/spaces/{spaceName}/pages/{pageName}/history/{version}/attachments[?start~=offset&number~=n] ===
586
587 * **HTTP Method:** GET
588 ** **Media types:**
589 *** application/xml (Attachments element)
590 ** **Description:** The list of attachments at a given page {version}.
591 ** **Status codes:**
592 *** 200: If the request was successful.
593 *** 401: If the user is not authorized.
594
595 === /wikis/{wikiName}/spaces/{spaceName}/pages/{pageName}/history/{version}/attachments/{attachmentName} ===
596
597 * **HTTP Method:** GET
598 ** **Media types:**
599 *** The same of the attachment media type.
600 ** **Description:** The attachment identified by {attachmentName} on a given page {version}.
601 ** **Status codes:**
602 *** 200: If the request was successful.
603 *** 401: If the user is not authorized.
604
605 === /wikis/{wikiName}/spaces/{spaceName}/pages/{pageName}/attachments/{attachmentName}/history ===
606
607 * **HTTP Method:** GET
608 ** **Media types:**
609 *** application/xml (Attachments element)
610 ** **Description:** The list of available version for the {attachmentName}
611 ** **Status codes:**
612 *** 200: If the request was successful.
613 *** 401: If the user is not authorized.
614
615 === /wikis/{wikiName}/spaces/{spaceName}/pages/{pageName}/attachments/{attachmentName}/history/{version} ===
616
617 * **HTTP Method:** GET
618 ** **Media types:**
619 *** The same of the attachment media type.
620 ** **Description:** The {attachmentName} at a given {version}
621 ** **Status codes:**
622 *** 200: If the request was successful.
623 *** 401: If the user is not authorized.
624
625 === /wikis/{wikiName}/spaces/{spaceName}/attachments[?name~=attachmentName&page~=pageName&author~=authorName&types~=attachmentTypeList&start~=offset&number~=n] ===
626
627 * **HTTP Method:** GET
628 ** **Media types:**
629 *** application/xml (Attachments element)
630 ** **Description:** The list of attachments of pages located in a given {spaceName}. Filters can be set for the name, page, author and/or types (comma separated list of strings) to include only attachments that match the given filters. This resource can be used to search for attachments in a space.
631 ** **Status codes:**
632 *** 200: If the request was successful.
633 *** 401: If the user is not authorized.
634
635 === /wikis/{wikiName}/attachments[?name~=attachmentName&page~=pageName&space~=spaceName&author~=authorName&types~=attachmentTypeList&start~=offset&number~=n] ===
636
637 * **HTTP Method:** GET
638 ** **Media types:**
639 *** application/xml (Attachments element)
640 ** **Description:** The list of attachments in a given {wikiName}. Filters can be set for the name, page, space, author and/or type (comma separated list of strings) to include only attachments that match the given filters. This resource can be used to search for attachments in a wiki.
641 ** **Status codes:**
642 *** 200: If the request was successful.
643 *** 401: If the user is not authorized.
644
645 == Object resources ==
646
647 === /wikis/{wikiName}/spaces/{spaceName}/pages/{pageName}/objects[?start~=offset&number~=n] ===
648
649 * **HTTP Method:** GET
650 ** **Media types:**
651 *** application/xml (Objects element)
652 ** **Description:** The list of objects associated to a page.
653 ** **Status codes:**
654 *** 200: If the request was successful.
655 *** 401: If the user is not authorized.
656
657 \\
658
659 * **HTTP Method:** POST
660 ** **Accepted media types:**
661 *** application/xml (Object element)
662 *** application/x-www-form-urlencoded (a set of property#name=value pairs representing properties and a field className)
663 ** **Media types:**
664 *** application/xml (Object element)
665 ** **Description:** Create a new object.
666 ** **Status codes:**
667 *** 201: If the object was created (The Location header will contain the URI associated to the newly created object).
668 *** 401: If the user is not authorized.
669
670 === /wikis/{wikiName}/spaces/{spaceName}/pages/{pageName}/objects/{className}[?start~=offset&number~=n] ===
671
672 * **HTTP Method:** GET
673 ** **Media types:**
674 *** application/xml (Objects element)
675 ** **Description:** The list of objects of a given {className} associated to a page.
676 ** **Status codes:**
677 *** 200: If the request was successful.
678 *** 401: If the user is not authorized.
679
680 === /wikis/{wikiName}/spaces/{spaceName}/pages/{pageName}/objects/{className}/{objectNumber} ===
681
682 * **HTTP Method:** GET
683 ** **Media types:**
684 *** application/xml (Object element)
685 ** **Description:** The object of type {className} identified by {objectNumber} associated to the given page.
686 ** **Status codes:**
687 *** 200: If the request was successful.
688 *** 401: If the user is not authorized.
689
690 \\
691
692 * **HTTP Method:** PUT
693 ** **Accepted media types:**
694 *** application/xml (Object element)
695 *** application/x-www-form-urlencoded (a set of property#name=value pairs representing properties)
696 ** **Media types:**
697 *** application/xml (Object element)
698 ** **Description:** Modify the object properties.
699 ** **Status codes:**
700 *** 202: If the object was updated.
701 *** 401: If the user is not authorized.
702
703 \\
704
705 * **HTTP Method:** DELETE
706 ** **Media types:**
707 ** **Description:** Delete the object.
708 ** **Status codes:**
709 *** 204: If the object was deleted.
710 *** 401: If the user is not authorized.
711
712 === /wikis/{wikiName}/spaces/{spaceName}/pages/{pageName}/objects/{className}/{objectNumber}/properties ===
713
714 * **HTTP Method:** GET
715 ** **Media types:**
716 *** application/xml (Properties element)
717 ** **Description:** The properties of the object of type {className} identified by {objectNumber} associated to the given page.
718 ** **Status codes:**
719 *** 200: If the request was successful.
720 *** 401: If the user is not authorized.
721
722 === /wikis/{wikiName}/spaces/{spaceName}/pages/{pageName}/objects/{className}/{objectNumber}/properties/{propertyName} ===
723
724 * **HTTP Method:** GET
725 ** **Media types:**
726 *** application/xml (Properties element)
727 ** **Description:** The property {propertyname} of the object of type {className} identified by {objectNumber} associated to the given page.
728 ** **Status codes:**
729 *** 200: If the request was successful.
730 *** 401: If the user is not authorized.
731
732 \\
733
734 * **HTTP Method:** PUT
735 ** **Accepted media types:**
736 *** application/xml (Property element)
737 *** text/plain
738 *** application/x-www-form-urlencoded (a field property#name=value pairs representing a property)
739 ** **Media types:**
740 *** application/xml (Property element)
741 ** **Description:** Modify the object properties.
742 ** **Status codes:**
743 *** 202: If the object was updated.
744 *** 401: If the user is not authorized.
745
746 === /wikis/{wikiName}/spaces/{spaceName}/pages/{pageName}/history/{version}/objects[?start~=offset&number~=n] ===
747
748 * **HTTP Method:** GET
749 ** **Media types:**
750 *** application/xml (Objects element)
751 ** **Description:** The list of objects associated to a page at a given {version}.
752 ** **Status codes:**
753 *** 200: If the request was successful.
754 *** 401: If the user is not authorized.
755
756 === /wikis/{wikiName}/spaces/{spaceName}/pages/{pageName}/history/{version}/objects/{className}/{objectNumber} ===
757
758 * **HTTP Method:** GET
759 ** **Media types:**
760 *** application/xml (Object element)
761 ** **Description:** The object of type {className} identified by {objectNumber} associated to the given page at a given {version}.
762 ** **Status codes:**
763 *** 200: If the request was successful.
764 *** 401: If the user is not authorized.
765
766 === /wikis/{wikiName}/spaces/{spaceName}/pages/{pageName}/history/{version}/objects/{className}/{objectNumber}/properties ===
767
768 * **HTTP Method:** GET
769 ** **Media types:**
770 *** application/xml (Properties element)
771 ** **Description:** The properties of the object of type {className} identified by {objectNumber} associated to the given page at a given {version}.
772 ** **Status codes:**
773 *** 200: If the request was successful.
774 *** 401: If the user is not authorized.
775
776 === /wikis/{wikiName}/spaces/{spaceName}/pages/{pageName}/history/{version}/objects/{className}/{objectNumber}/properties/{propertyName} ===
777
778 * **HTTP Method:** GET
779 ** **Media types:**
780 *** application/xml (Properties element)
781 ** **Description:** The property {propertyname} of the object of type {className} identified by {objectNumber} associated to the given page at a given {version}.
782 ** **Status codes:**
783 *** 200: If the request was successful.
784 *** 401: If the user is not authorized.
785
786 === /wikis/{wikiName}/class/{className}/objects ===
787
788 * **HTTP Method:** GET
789 ** **Media types:**
790 *** application/xml (Objects element)
791 ** **Description:** The list of all the objects of a given {className}.
792 ** **Status codes:**
793 *** 200: If the request was successful.
794 *** 401: If the user is not authorized.
795
796 == Class resources ==
797
798 === /wikis/{wikiName}/classes[?start~=offset&number~=n] ===
799
800 * **HTTP Method:** GET
801 ** **Media types:**
802 *** application/xml (Classes element)
803 ** **Description:** The list of all the classes defined in the wiki {wikiName}
804 ** **Status codes:**
805 *** 200: If the request was successful.
806 *** 401: If the user is not authorized.
807
808 === /wikis/{wikiName}/classes/{className} ===
809
810 * **HTTP Method:** GET
811 ** **Media types:**
812 *** application/xml (Class element)
813 ** **Description:** The {className} definition
814 ** **Status codes:**
815 *** 200: If the request was successful.
816 *** 401: If the user is not authorized.
817
818 === /wikis/{wikiName}/classes/{className}/properties ===
819
820 * **HTTP Method:** GET
821 ** **Media types:**
822 *** application/xml (Properties element)
823 ** **Description:** The properties of the class {className}.
824 ** **Status codes:**
825 *** 200: If the request was successful.
826 *** 401: If the user is not authorized.
827
828 === /wikis/{wikiName}/classes/{className}/properties/{property} ===
829
830 * **HTTP Method:** GET
831 ** **Media types:**
832 *** application/xml (Property element)
833 ** **Description:** The property {property} of the class {className}.
834 ** **Status codes:**
835 *** 200: If the request was successful.
836 *** 401: If the user is not authorized.
837
838 == Other resources ==
839
840 === /wikis/{wikiName}/modifications[?start~=offset&number~=n&date~=t] ===
841
842 * **HTTP Method:** GET
843 ** **Media types:**
844 *** application/xml (Modifications element)
845 ** **Description:** The list of the latest modification made to the wiki {wikiName} starting from time t (t is expressed in milliseconds from 1970 of the starting date)
846 ** **Status codes:**
847 *** 200: If the request was successful.
848 *** 401: If the user is not authorized.
849
850 = Custom resources =
851
852 It's possible to easily add any REST resource by registering a ##org.xwiki.rest.XWikiResource## java component on your wiki (see [[Component guide>>DevGuide.WritingComponents]] for more details).
853
854 {{code language="java"}}
855 package org.xwiki.contrib.rest;
856
857 import javax.ws.rs.DefaultValue;
858 import javax.ws.rs.GET;
859 import javax.ws.rs.Path;
860
861 import org.xwiki.component.annotation.Component;
862 import org.xwiki.rest.XWikiResource;
863
864 @Component("org.xwiki.contrib.rest.HelloWordResource")
865 @Path("/myresources/{myresourcename}")
866 class HelloWorldResource extends XWikiResource {
867 @GET
868 public String get(@PathParam("myresourcename") @DefaultValue("world") String myresourcename)
869 {
870 return "Hello " + myresourcename;
871 }
872 }
873 {{/code}}
874
875 The name of the component has to be the class FQN.
876
877 You can find more examples on [[https://github.com/xwiki/xwiki-platform/tree/master/xwiki-platform-core/xwiki-platform-rest/xwiki-platform-rest-server/src/main/java/org/xwiki/rest/resources]].

Get Connected