Wiki source code of The XWiki RESTful API

Version 25.1 by Ludovic Dubost on 2011/01/19

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

Get Connected