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
74 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).
75
76 == The "HATEOAS" Graph ==
77
78 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.
79
80 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.
81
82 = Interacting with the XWiki RESTful API =
83
84 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!
85 If you want to write more complex programs you might download an HTTP library for your favorite language (e.g., [[http://hc.apache.org/]]).
86
87 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.
88
89 If you use this approach (Apache HTTP Client + JAXB) you will find yourself writing some code like this:
90
91 {{code language="java"}}
92 import javax.xml.bind.JAXBContext;
93 import javax.xml.bind.Unmarshaller;
94
95 import org.apache.commons.httpclient.HttpClient;
96 import org.apache.commons.httpclient.methods.GetMethod;
97 import org.xwiki.rest.model.jaxb.Page;
98
99 ...
100 HttpClient httpClient = new HttpClient();
101 JAXBContext context = JAXBContext.newInstance("org.xwiki.rest.model.jaxb");
102 Unmarshaller unmarshaller = context.createUnmarshaller();
103
104 GetMethod getMethod = new GetMethod("http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/Main/pages/WebHome");
105 getMethod.addRequestHeader("Accept", "application/xml");
106 httpClient.executeMethod(getMethod);
107
108 Page page = (Page) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
109 {{/code}}
110
111 And you will have all the information about the Main.WebHome page in the Page object, without the need of handling XML directly.
112
113 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.
114
115 By using curl, the previous example would have been:
116
117 {{code language="xml"}}
118 $ curl http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/Main/pages/WebHome
119 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
120 <page xmlns="http://www.xwiki.org">
121 <link rel="http://www.xwiki.org/rel/space" href="http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/Main"/>
122 ...
123 {{/code}}
124
125 == Authentication ==
126
127 The XWiki RESTful API supports two types of authentication:
128
129 * **HTTP BASIC Auth**: You provide your credentials using the Authorization HTTP header
130 * **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.
131
132 If you don't provide any credentials the XWiki RESTful API will recognize you as a XWiki.Guest user.
133
134 So if you have, let's say a Main.PrivatePage, and you try to do:
135
136 {{code language="none"}}
137 $ curl -v http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/Main/pages/PrivatePage
138 ...
139 < HTTP/1.1 401 Unauthorized
140 ...
141 {{/code}}
142
143 You will get an Unauthorized empty response.
144
145 On the contrary, by specifying Admin credentials you gain access to the actual page:
146
147 {{code language="xml"}}
148 $ curl -u Admin:admin http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/Main/pages/PrivatePage
149 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
150 <page xmlns="http://www.xwiki.org">
151 <link rel="http://www.xwiki.org/rel/space" href="http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/Main"/>
152 ...
153 <content>Only admin can see this</content>
154 </page>
155 {{/code}}
156
157 == Sending representations ==
158
159 Many resources are modifiable, so you can send representations in order to change the state of those resources (e.g., pages).
160 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).
161
162 Resource update is usually done by using the PUT method, while resource creation is done via PUT or POST.
163
164 For example, in order to create a page you might do the following:
165
166 {{code language="xml"}}
167 $ 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
168 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
169 <page xmlns="http://www.xwiki.org">
170 <link rel="http://www.xwiki.org/rel/space" href="http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/Main"/>
171 ...
172 <version>1.1</version>
173 <majorVersion>1</majorVersion>
174 <minorVersion>1</minorVersion>
175 <created>2009-03-21+01:00</created>
176 <creator>XWiki.Admin</creator>
177 <modified>2009-03-21+01:00</modified>
178 <modifier>XWiki.Admin</modifier>
179 <content>This is a new page</content>
180 </page>
181 {{/code}}
182
183 Where newpage.xml is an XML file containing
184
185 {{code language="xml"}}
186 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
187 <page xmlns="http://www.xwiki.org">
188 <title>Hello world</title>
189 <content>This is a new page</content>
190 </page>
191 {{/code}}
192
193 The page has been created and is accessible. Subsequent PUT requests to the page URI will modify its content.
194
195 == Overcoming browser limitations ==
196
197 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.
198
199 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.
200
201 This overriding mechanism allows the interaction with the XWiki RESTful API by using any kind of browser.
202
203 == PUT vs POST ==
204
205 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.
206
207 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.
208
209 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.
210
211 = XWiki RESTful API Documentation =
212
213 In this section you will find the documentation of the whole XWiki RESTful API.
214
215 **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]]
216
217 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.
218
219 == Root resources ==
220
221 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)
222
223 === / ===
224
225 * **HTTP Method:** GET
226 ** **Media types:**
227 *** application/xml (XWiki element)
228 ** **Description:** Retrieves the entry root description containing information about the server.
229 ** **Status codes:**
230 *** 200: If the request was successful.
231
232 === /wikis ===
233
234 * **HTTP Method:** GET
235 ** **Media types:**
236 *** application/xml (Wikis element)
237 ** **Description:** Retrieves the entry root description containing information about the server.
238 ** **Status codes:**
239 *** 200: If the request was successful.
240
241 === /wikis/{wikiName}/search?q~={keywords}~[~[&scope~={name,content,title,objects}...]&number~=n] ===
242
243 * **HTTP Method:** GET
244 ** **Media types:**
245 *** application/xml (SearchResults element)
246 ** **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}
247 ** **Status codes:**
248 *** 200: If the request was successful.
249
250 == Space resources ==
251
252 === /wikis/{wikiName}/spaces[?start~=offset&number~=n] ===
253
254 * **HTTP Method:** GET
255 ** **Media types:**
256 *** application/xml (Spaces element)
257 ** **Description:** Retrieves the list of spaces available in the {wikiName} wiki.
258 ** **Status codes:**
259 *** 200: If the request was successful.
260
261 === /wikis/{wikiName}/spaces/{spaceName}/search?q~={keywords}~[~[&scope~={name,content,title,objects}...]&number~=n] ===
262
263 * **HTTP Method:** GET
264 ** **Media types:**
265 *** application/xml (Search results element)
266 ** **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}
267 ** **Status codes:**
268 *** 200: If the request was successful.
269 *** 401: If the user is not authorized.
270
271 == Page resources ==
272
273 === /wikis/{wikiName}/spaces/{spaceName}/pages[?start~=offset&number~=n] ===
274
275 * **HTTP Method:** GET
276 ** **Media types:**
277 *** application/xml (Pages element)
278 ** **Description:** The list of pages in the space {spaceName}
279 ** **Status codes:**
280 *** 200: If the request was successful
281 *** 401: If the user is not authorized.
282
283 === /wikis/{wikiName}/spaces/{spaceName}/pages/{pageName} ===
284
285 * **HTTP Method:** GET
286 ** **Media types:**
287 *** application/xml (Page element)
288 ** **Description:**
289 ** **Status codes:**
290 *** 200: If the request was successful.
291 *** 401: If the user is not authorized.
292
293 \\
294
295 * **HTTP Method:** PUT
296 ** **Accepted Media types:**
297 *** application/xml (Page element)
298 *** text/plain (Only page content)
299 *** application/x-www-form-urlencoded (allowed field names: title, parent, content)
300 ** **Media types:**
301 *** application/xml (Page element)
302 ** **Description:** Create or updates a page.
303 ** **Status codes:**
304 *** 201: If the page was created.
305 *** 202: If the page was updated.
306 *** 304: If the page was not modified.
307 *** 401: If the user is not authorized.
308
309 \\
310
311 * **HTTP Method:** DELETE
312 ** **Media types:**
313 *** application/xml (Page element)
314 ** **Description:** Delete the page.
315 ** **Status codes:**
316 *** 204: If the request was successful.
317 *** 401: If the user is not authorized.
318
319 === /wikis/{wikiName}/spaces/{spaceName}/pages/{pageName}/history[?start~=offset&number~=n] ===
320
321 * **HTTP Method:** GET
322 ** **Media types:**
323 *** application/xml (History element)
324 ** **Description:** The list of all the versions of the given page.
325 ** **Status codes:**
326 *** 200: If the request was successful.
327 *** 401: If the user is not authorized.
328
329 === /wikis/{wikiName}/spaces/{spaceName}/pages/{pageName}/history/{version} ===
330
331 * **HTTP Method:** GET
332 ** **Media types:**
333 *** application/xml (Page element)
334 ** **Description:** The page at version {version}
335 ** **Status codes:**
336 *** 200: If the request was successful.
337 *** 401: If the user is not authorized.
338
339 ==== /wikis/{wikiName}/spaces/{spaceName}/pages/{pageName}/translations[?start~=offset&number~=n] ====
340
341 * **HTTP Method:** GET
342 ** **Media types:**
343 *** application/xml (Translations element)
344 ** **Description:** The list of available translation for the page
345 ** **Status codes:**
346 *** 200: If the request was successful.
347 *** 401: If the user is not authorized.
348
349 === /wikis/{wikiName}/spaces/{spaceName}/pages/{pageName}/translations/{language} ===
350
351 * **HTTP Method:** GET
352 ** **Media types:**
353 *** application/xml (Page element)
354 ** **Description:** The page at in the given {language}.
355 ** **Status codes:**
356 *** 200: If the request was successful.
357 *** 401: If the user is not authorized.
358
359 \\
360
361 * **HTTP Method:** PUT
362 ** **Accepted Media types:**
363 *** application/xml (Page element)
364 *** text/plain (Only page content)
365 *** application/x-www-form-urlencoded (allowed field names: title, parent, content)
366 ** **Media types:**
367 *** application/xml (Page element)
368 ** **Description:** Create or updates a page translation.
369 ** **Status codes:**
370 *** 201: If the page was created.
371 *** 202: If the page was updated.
372 *** 304: If the page was not modified.
373 *** 401: If the user is not authorized.
374
375 \\
376
377 * **HTTP Method:** DELETE
378 ** **Media types:**
379 *** application/xml (Page element)
380 ** **Description:** Delete the page translation.
381 ** **Status codes:**
382 *** 204: If the request was successful.
383 *** 401: If the user is not authorized.
384
385 === /wikis/{wikiName}/spaces/{spaceName}/pages/{pageName}/translations/{language}/history ===
386
387 * **HTTP Method:** GET
388 ** **Media types:**
389 *** application/xml (History element)
390 ** **Description:** The list of all the available revisions of the page in a given {language}.
391 ** **Status codes:**
392 *** 200: If the request was successful.
393 *** 401: If the user is not authorized.
394
395 === /wikis/{wikiName}/spaces/{spaceName}/pages/{pageName}/translations/{lang}/history/{version} ===
396
397 * **HTTP Method:** GET
398 ** **Media types:**
399 *** application/xml (Page element)
400 ** **Description:** A page at a given {version} in a given {language}.
401 ** **Status codes:**
402 *** 200: If the request was successful.
403 *** 401: If the user is not authorized.
404
405 === /wikis/{wikiName}/spaces/{spaceName}/pages/{pageName}/children ===
406
407 * **HTTP Method:** GET
408 ** **Media types:**
409 *** application/xml (Pages element)
410 ** **Description:** The list of the children of a given page.
411 ** **Status codes:**
412 *** 200: If the request was successful.
413 *** 401: If the user is not authorized.
414
415 == Tag resources ==
416
417 === /wikis/{wikiName}/spaces/{spaceName}/pages/{pageName}/tags ===
418
419 * **HTTP Method:** GET
420 ** **Media types:**
421 *** application/xml (Tags element)
422 ** **Description:** List page tags.
423 ** **Status codes:**
424 *** 200: If the request was successful.
425 *** 401: If the user is not authorized.
426
427 \\
428
429 * **HTTP Method:** PUT
430 ** **Accepted Media types:**
431 *** application/xml (Tag element)
432 *** text/plain
433 *** application/x-www-form-urlencoded (allowed field names: tag)
434 ** **Media types:**
435 *** application/xml (Tags element)
436 ** **Description:** Add a tag to the page.
437 ** **Status codes:**
438 *** 202: If the request was successful.
439 *** 401: If the user is not authorized.
440
441 === /wikis/{wikiName}/tags ===
442
443 * **HTTP Method:** GET
444 ** **Media types:**
445 *** application/xml (Tags element)
446 ** **Description:** The list of all available tags
447 ** **Status codes:**
448 *** 200: If the request was successful.
449 *** 401: If the user is not authorized.
450
451 === /wikis/{wikiName}/tags/{tag1}[,{tag2},{tag3}...][?start~=offset&number~=n] ===
452
453 * **HTTP Method:** GET
454 ** **Media types:**
455 *** application/xml (Pages element)
456 ** **Description:** The list of pages having the specified tags.
457 ** **Status codes:**
458 *** 200: If the request was successful.
459 *** 401: If the user is not authorized.
460
461 == Comments resources ==
462
463 === /wikis/{wikiName}/spaces/{spaceName}/pages/{pageName}/comments[?start~=offset&number~=n] ===
464
465 * **HTTP Method:** GET
466 ** **Media types:**
467 *** application/xml (Comments element)
468 ** **Description:** The list of comments on a given page.
469 ** **Status codes:**
470 *** 200: If the request was successful.
471 *** 401: If the user is not authorized.
472
473 \\
474
475 * **HTTP Method:** POST
476 ** **Accepted Media types:**
477 *** application/xml (Comment element)
478 *** text/plain
479 *** application/x-www-form-urlencoded - allowed field names: ##text##, ##replyTo## (object number of the replied comment, since XE 2.3)
480 ** **Media types:**
481 *** application/xml (Comment element)
482 ** **Description:** Create a comment on the given page.
483 ** **Status codes:**
484 *** 201: If the comment was created. (The Location header will contain the URI where the comment has been created.)
485 *** 401: If the user is not authorized.
486
487 === /wikis/{wikiName}/spaces/{spaceName}/pages/{pageName}/comments/{commentId} ===
488
489 * **HTTP Method:** GET
490 ** **Media types:**
491 *** application/xml (Comment element)
492 ** **Description:** A specific comment on a page
493 ** **Status codes:**
494 *** 200: If the request was successful.
495 *** 401: If the user is not authorized.
496
497 === /wikis/{wikiName}/spaces/{spaceName}/pages/{pageName}/history/{version}/comments ===
498
499 * **HTTP Method:** GET
500 ** **Media types:**
501 *** application/xml (Comments element)
502 ** **Description:** The list of comments at a specific page {version}.
503 ** **Status codes:**
504 *** 200: If the request was successful.
505 *** 401: If the user is not authorized.
506
507 === /wikis/{wikiName}/spaces/{spaceName}/pages/{pageName}/history/{version}/comments/{commentId} ===
508
509 * **HTTP Method:** GET
510 ** **Media types:**
511 *** application/xml (Comment element)
512 ** **Description:** A comment at a specific page {version}.
513 ** **Status codes:**
514 *** 200: If the request was successful.
515 *** 401: If the user is not authorized.
516
517 == Attachments resources ==
518
519 === /wikis/{wikiName}/spaces/{spaceName}/pages/{pageName}/attachments[?start~=offset&number~=n] ===
520
521 * **HTTP Method:** GET
522 ** **Media types:**
523 *** application/xml (Attachments element)
524 ** **Description:** The list of attachments of a given page.
525 ** **Status codes:**
526 *** 200: If the request was successful.
527 *** 401: If the user is not authorized.
528
529 === /wikis/{wikiName}/spaces/{spaceName}/pages/{pageName}/attachments/{attachmentName} ===
530
531 * **HTTP Method:** GET
532 ** **Media types:**
533 *** The same of the attachment media type.
534 ** **Description:** The attachment identified by {attachmentName} on a given page.
535 ** **Status codes:**
536 *** 200: If the request was successful.
537 *** 401: If the user is not authorized.
538
539 \\
540
541 * **HTTP Method:** PUT
542 ** **Accepted media types:**
543 *** **/**
544 ** **Media types:**
545 *** application/xml (AttachmentSummary element)
546 ** **Description:** Create an attachment identified by {attachmentName} on a given page.
547 ** **Status codes:**
548 *** 201: If the attachment was created.
549 *** 202: If the attachment was updated.
550 *** 401: If the user is not authorized.
551
552 \\
553
554 * **HTTP Method:** DELETE
555 ** **Media types:**
556 ** **Description:** Delete the attachment identified by {attachmentName} on a given page.
557 ** **Status codes:**
558 *** 204: If the attachment was deleted.
559 *** 401: If the user is not authorized.
560
561 === /wikis/{wikiName}/spaces/{spaceName}/pages/{pageName}/history/{version}/attachments[?start~=offset&number~=n] ===
562
563 * **HTTP Method:** GET
564 ** **Media types:**
565 *** application/xml (Attachments element)
566 ** **Description:** The list of attachments at a given page {version}.
567 ** **Status codes:**
568 *** 200: If the request was successful.
569 *** 401: If the user is not authorized.
570
571 === /wikis/{wikiName}/spaces/{spaceName}/pages/{pageName}/history/{version}/attachments/{attachmentName} ===
572
573 * **HTTP Method:** GET
574 ** **Media types:**
575 *** The same of the attachment media type.
576 ** **Description:** The attachment identified by {attachmentName} on a given page {version}.
577 ** **Status codes:**
578 *** 200: If the request was successful.
579 *** 401: If the user is not authorized.
580
581 === /wikis/{wikiName}/spaces/{spaceName}/pages/{pageName}/attachments/{attachmentName}/history ===
582
583 * **HTTP Method:** GET
584 ** **Media types:**
585 *** application/xml (Attachments element)
586 ** **Description:** The list of available version for the {attachmentName}
587 ** **Status codes:**
588 *** 200: If the request was successful.
589 *** 401: If the user is not authorized.
590
591 === /wikis/{wikiName}/spaces/{spaceName}/pages/{pageName}/attachments/{attachmentName}/history/{version} ===
592
593 * **HTTP Method:** GET
594 ** **Media types:**
595 *** The same of the attachment media type.
596 ** **Description:** The {attachmentName} at a given {version}
597 ** **Status codes:**
598 *** 200: If the request was successful.
599 *** 401: If the user is not authorized.
600
601 == Object resources ==
602
603 === /wikis/{wikiName}/spaces/{spaceName}/pages/{pageName}/objects[?start~=offset&number~=n] ===
604
605 * **HTTP Method:** GET
606 ** **Media types:**
607 *** application/xml (Objects element)
608 ** **Description:** The list of objects associated to a page.
609 ** **Status codes:**
610 *** 200: If the request was successful.
611 *** 401: If the user is not authorized.
612
613 \\
614
615 * **HTTP Method:** POST
616 ** **Accepted media types:**
617 *** application/xml (Object element)
618 *** application/x-www-form-urlencoded (a set of property#name=value pairs representing properties and a field className)
619 ** **Media types:**
620 *** application/xml (Object element)
621 ** **Description:** Create a new object.
622 ** **Status codes:**
623 *** 201: If the object was created (The Location header will contain the URI associated to the newly created object).
624 *** 401: If the user is not authorized.
625
626 === /wikis/{wikiName}/spaces/{spaceName}/pages/{pageName}/objects/{className}[?start~=offset&number~=n] ===
627
628 * **HTTP Method:** GET
629 ** **Media types:**
630 *** application/xml (Objects element)
631 ** **Description:** The list of objects of a given {className} associated to a page.
632 ** **Status codes:**
633 *** 200: If the request was successful.
634 *** 401: If the user is not authorized.
635
636 === /wikis/{wikiName}/spaces/{spaceName}/pages/{pageName}/objects/{className}/{objectNumber} ===
637
638 * **HTTP Method:** GET
639 ** **Media types:**
640 *** application/xml (Object element)
641 ** **Description:** The object of type {className} identified by {objectNumber} associated to the given page.
642 ** **Status codes:**
643 *** 200: If the request was successful.
644 *** 401: If the user is not authorized.
645
646 \\
647
648 * **HTTP Method:** PUT
649 ** **Accepted media types:**
650 *** application/xml (Object element)
651 *** application/x-www-form-urlencoded (a set of property#name=value pairs representing properties)
652 ** **Media types:**
653 *** application/xml (Object element)
654 ** **Description:** Modify the object properties.
655 ** **Status codes:**
656 *** 202: If the object was updated.
657 *** 401: If the user is not authorized.
658
659 \\
660
661 * **HTTP Method:** DELETE
662 ** **Media types:**
663 ** **Description:** Delete the object.
664 ** **Status codes:**
665 *** 204: If the object was deleted.
666 *** 401: If the user is not authorized.
667
668 === /wikis/{wikiName}/spaces/{spaceName}/pages/{pageName}/objects/{className}/{objectNumber}/properties ===
669
670 * **HTTP Method:** GET
671 ** **Media types:**
672 *** application/xml (Properties element)
673 ** **Description:** The properties of the object of type {className} identified by {objectNumber} associated to the given page.
674 ** **Status codes:**
675 *** 200: If the request was successful.
676 *** 401: If the user is not authorized.
677
678 === /wikis/{wikiName}/spaces/{spaceName}/pages/{pageName}/objects/{className}/{objectNumber}/properties/{propertyName} ===
679
680 * **HTTP Method:** GET
681 ** **Media types:**
682 *** application/xml (Properties element)
683 ** **Description:** The property {propertyname} of the object of type {className} identified by {objectNumber} associated to the given page.
684 ** **Status codes:**
685 *** 200: If the request was successful.
686 *** 401: If the user is not authorized.
687
688 \\
689
690 * **HTTP Method:** PUT
691 ** **Accepted media types:**
692 *** application/xml (Property element)
693 *** text/plain
694 *** application/x-www-form-urlencoded (a field property#name=value pairs representing a property)
695 ** **Media types:**
696 *** application/xml (Property element)
697 ** **Description:** Modify the object properties.
698 ** **Status codes:**
699 *** 202: If the object was updated.
700 *** 401: If the user is not authorized.
701
702 === /wikis/{wikiName}/spaces/{spaceName}/pages/{pageName}/history/{version}/objects[?start~=offset&number~=n] ===
703
704 * **HTTP Method:** GET
705 ** **Media types:**
706 *** application/xml (Objects element)
707 ** **Description:** The list of objects associated to a page at a given {version}.
708 ** **Status codes:**
709 *** 200: If the request was successful.
710 *** 401: If the user is not authorized.
711
712 === /wikis/{wikiName}/spaces/{spaceName}/pages/{pageName}/history/{version}/objects/{className}/{objectNumber} ===
713
714 * **HTTP Method:** GET
715 ** **Media types:**
716 *** application/xml (Object element)
717 ** **Description:** The object of type {className} identified by {objectNumber} associated to the given page at a given {version}.
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}/history/{version}/objects/{className}/{objectNumber}/properties ===
723
724 * **HTTP Method:** GET
725 ** **Media types:**
726 *** application/xml (Properties element)
727 ** **Description:** The properties of the object of type {className} identified by {objectNumber} associated to the given page at a given {version}.
728 ** **Status codes:**
729 *** 200: If the request was successful.
730 *** 401: If the user is not authorized.
731
732 === /wikis/{wikiName}/spaces/{spaceName}/pages/{pageName}/history/{version}/objects/{className}/{objectNumber}/properties/{propertyName} ===
733
734 * **HTTP Method:** GET
735 ** **Media types:**
736 *** application/xml (Properties element)
737 ** **Description:** The property {propertyname} of the object of type {className} identified by {objectNumber} associated to the given page at a given {version}.
738 ** **Status codes:**
739 *** 200: If the request was successful.
740 *** 401: If the user is not authorized.
741
742 === /wikis/{wikiName}/class/{className}/objects ===
743
744 * **HTTP Method:** GET
745 ** **Media types:**
746 *** application/xml (Objects element)
747 ** **Description:** The list of all the objects of a given {className}.
748 ** **Status codes:**
749 *** 200: If the request was successful.
750 *** 401: If the user is not authorized.
751
752 == Class resources ==
753
754 === /wikis/{wikiName}/classes[?start~=offset&number~=n] ===
755
756 * **HTTP Method:** GET
757 ** **Media types:**
758 *** application/xml (Classes element)
759 ** **Description:** The list of all the classes defined in the wiki {wikiName}
760 ** **Status codes:**
761 *** 200: If the request was successful.
762 *** 401: If the user is not authorized.
763
764 === /wikis/{wikiName}/classes/{className} ===
765
766 * **HTTP Method:** GET
767 ** **Media types:**
768 *** application/xml (Class element)
769 ** **Description:** The {className} definition
770 ** **Status codes:**
771 *** 200: If the request was successful.
772 *** 401: If the user is not authorized.
773
774 === /wikis/{wikiName}/classes/{className}/properties ===
775
776 * **HTTP Method:** GET
777 ** **Media types:**
778 *** application/xml (Properties element)
779 ** **Description:** The properties of the class {className}.
780 ** **Status codes:**
781 *** 200: If the request was successful.
782 *** 401: If the user is not authorized.
783
784 === /wikis/{wikiName}/classes/{className}/properties/{property} ===
785
786 * **HTTP Method:** GET
787 ** **Media types:**
788 *** application/xml (Property element)
789 ** **Description:** The property {property} of the class {className}.
790 ** **Status codes:**
791 *** 200: If the request was successful.
792 *** 401: If the user is not authorized.
793
794 == Other resources ==
795
796 === /wikis/{wikiName}/modifications[?start~=offset&number~=n&date~=t] ===
797
798 * **HTTP Method:** GET
799 ** **Media types:**
800 *** application/xml (Modifications element)
801 ** **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)
802 ** **Status codes:**
803 *** 200: If the request was successful.
804 *** 401: If the user is not authorized.
805
806 = Custom resources =
807
808 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).
809
810 {{code language="java"}}
811 package org.xwiki.contrib.rest;
812
813 import javax.ws.rs.DefaultValue;
814 import javax.ws.rs.GET;
815 import javax.ws.rs.Path;
816
817 import org.xwiki.component.annotation.Component;
818 import org.xwiki.rest.XWikiResource;
819
820 @Component("org.xwiki.contrib.rest.HelloWordResource")
821 @Path("/myresources/{myresourcename}")
822 class HelloWorldResource extends XWikiResource {
823 @GET
824 public String get(@PathParam("myresourcename") @DefaultValue("world") String myresourcename)
825 {
826 return "Hello " + myresourcename;
827 }
828 }
829 {{/code}}
830
831 The name of the component has to be the class FQN.
832
833 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