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 ##/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#Central_principle]])
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>>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]].
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 |{{{http://www.xwiki.org/rel/syntaxes}}}|The representation for a syntax resource.
72
73 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).
74
75 == The "HATEOAS" Graph ==
76
77 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://code.google.com/p/uri-templates/]] representing classes of resources. Edges are the possible links that you might find in a representation of a given resource, and their associated relations.
78
79 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.
80
81 = Interacting with the XWiki RESTful API =
82
83 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!
84 If you want to write more complex programs you might download an HTTP library for your favorite language (e.g., [[http://hc.apache.org/]]), see [[this post>>xwiki:Blog.Use the Apache HTTP library to interact with the XWiki RESTful API]] by [[Mohamed Boussaa>>xwiki:XWiki.mouhb]].
85
86 Java users might take advantage of the [[JAXB>>http://jaxb.java.net/]] framework and its [[XJC binding compiler>>http://jaxb.java.net/2.2.4/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.
87
88 If you use this approach (Apache HTTP Client + JAXB) you will find yourself writing some code like this:
89
90 {{code language="java"}}
91 import javax.xml.bind.JAXBContext;
92 import javax.xml.bind.Unmarshaller;
93
94 import org.apache.commons.httpclient.HttpClient;
95 import org.apache.commons.httpclient.methods.GetMethod;
96 import org.xwiki.rest.model.jaxb.Page;
97
98 ...
99 HttpClient httpClient = new HttpClient();
100 JAXBContext context = JAXBContext.newInstance("org.xwiki.rest.model.jaxb");
101 Unmarshaller unmarshaller = context.createUnmarshaller();
102
103 GetMethod getMethod = new GetMethod("http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/Main/pages/WebHome");
104 getMethod.addRequestHeader("Accept", "application/xml");
105 httpClient.executeMethod(getMethod);
106
107 Page page = (Page) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
108 {{/code}}
109
110 And you will have all the information about the Main.WebHome page in the Page object, without the need of handling XML directly.
111
112 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.
113
114 By using curl, the previous example would have been:
115
116 {{code language="xml"}}
117 $ curl http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/Main/pages/WebHome
118 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
119 <page xmlns="http://www.xwiki.org">
120 <link rel="http://www.xwiki.org/rel/space" href="http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/Main"/>
121 ...
122 {{/code}}
123
124 == Authentication ==
125
126 The XWiki RESTful API supports two types of authentication:
127
128 * **HTTP BASIC Auth**: You provide your credentials using the Authorization HTTP header
129 * **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.
130
131 If you don't provide any credentials the XWiki RESTful API will recognize you as a XWiki.Guest user.
132
133 So if you have, let's say a Main.PrivatePage, and you try to do:
134
135 {{code language="none"}}
136 $ curl -v http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/Main/pages/PrivatePage
137 ...
138 < HTTP/1.1 401 Unauthorized
139 ...
140 {{/code}}
141
142 You will get an Unauthorized empty response.
143
144 On the contrary, by specifying Admin credentials you gain access to the actual page:
145
146 {{code language="xml"}}
147 $ curl -u Admin:admin http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/Main/pages/PrivatePage
148 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
149 <page xmlns="http://www.xwiki.org">
150 <link rel="http://www.xwiki.org/rel/space" href="http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/Main"/>
151 ...
152 <content>Only admin can see this</content>
153 </page>
154 {{/code}}
155
156 == Sending representations ==
157
158 Many resources are modifiable, so you can send representations in order to change the state of those resources (e.g., pages).
159 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).
160
161 Resource update is usually done by using the PUT method, while resource creation is done via PUT or POST.
162
163 For example, in order to create a page you might do the following:
164
165 {{code language="xml"}}
166 $ 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
167 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
168 <page xmlns="http://www.xwiki.org">
169 <link rel="http://www.xwiki.org/rel/space" href="http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/Main"/>
170 ...
171 <version>1.1</version>
172 <majorVersion>1</majorVersion>
173 <minorVersion>1</minorVersion>
174 <created>2009-03-21+01:00</created>
175 <creator>XWiki.Admin</creator>
176 <modified>2009-03-21+01:00</modified>
177 <modifier>XWiki.Admin</modifier>
178 <content>This is a new page</content>
179 </page>
180 {{/code}}
181
182 Where newpage.xml is an XML file containing
183
184 {{code language="xml"}}
185 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
186 <page xmlns="http://www.xwiki.org">
187 <title>Hello world</title>
188 <syntax>xwiki/2.0</syntax>
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 You can specify a subset of the three elements {{{title}}}, {{{syntax}}}, and {{{content}}} in the XML when updating/creating a page.
196 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.
197
198 == Overcoming browser limitations ==
199
200 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.
201
202 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.
203
204 This overriding mechanism allows the interaction with the XWiki RESTful API by using any kind of browser.
205
206 == PUT vs POST ==
207
208 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.
209
210 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.
211
212 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.
213
214 = XWiki RESTful API Documentation =
215
216 In this section you will find the documentation of the whole XWiki RESTful API.
217
218 **application/xml** representations refers 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]].
219
220 Resource URIs are specified using [[URI templates>>http://code.google.com/p/uri-templates/]]. Bracketed elements are formal parameters and should be instantiated to actual values in order to retrieve the associated resource.
221
222 == Root resources ==
223
224 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)
225
226 === / ===
227
228 * **HTTP Method:** GET
229 ** **Media types:**
230 *** application/xml (XWiki element)
231 ** **Description:** Retrieves the entry root description containing information about the server (currently returns the XWiki product Version).
232 ** **Status codes:**
233 *** 200: If the request was successful.
234
235 === /syntaxes ===
236
237 * **HTTP Method:** GET
238 ** **Media types:**
239 *** application/xml (Syntaxes element)
240 ** **Description:** The list of syntaxes supported by the XWiki instance.
241 ** **Status codes:**
242 *** 200: If the request was successful.
243
244 === /wikis ===
245
246 * **HTTP Method:** GET
247 ** **Media types:**
248 *** application/xml (Wikis element)
249 ** **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'.
250 ** **Status codes:**
251 *** 200: If the request was successful.
252
253 === /wikis/query?q~={query}&wikis~=wikiList[&distinct~={true,false}][&order~={asc,desc}][&start~=n][&number~=n][&prettyNames~={true,false}] ===
254
255 * **HTTP Method:** GET
256 ** **Media types:**
257 *** application/xml (SearchResults element)
258 ** **Description:** Search resources (pages and attachments):
259 *** [since 6.4] using a SOLR query (handled by the [[SOLR Query module>>extensions:Extension.Solr Search Query API]]) on the wikis that are specified as a comma separated list in the //wikis// parameter.
260 *** [before 6.4] using a Lucene query (handled by the [[Lucene Plugin>>extensions:Extension.Lucene Plugin]]) on the wikis that are specified as a comma separated list in the //wikis// parameter.
261 ** **Status codes:**
262 *** 200: If the request was successful.
263
264 === /wikis/{wikiName} ===
265
266 * **HTTP Method:** GET
267 ** **Media types:**
268 *** application/xml (Wiki element)
269 ** **Description:** information about the wiki
270 ** **Status codes:**
271 *** 200: If the request was successful.
272
273 * **HTTP Method:** POST
274 ** **Accepted Media types:**
275 *** octet/stream (A XAR file)
276 ** **Media types:**
277 *** application/xml (Wiki element)
278 ** **Query parameters**
279 *** backup={true/false} - import XAR as a backup XAR
280 *** history={RESET/REPLACE/ADD} - history importing
281 ** **Description:** import a XAR in a wiki.
282 ** **Status codes:**
283 *** 200: If the request was successful.
284
285 === /wikis/{wikiName}/search?q~={keywords}~[~[&scope~={name,content,title,objects}...]&start~=n][&number~=n][&orderField~=field&order~={asc,desc}][distinct~={true,false}][&prettyNames~={true,false}] ===
286
287 * **HTTP Method:** GET
288 ** **Media types:**
289 *** application/xml (SearchResults element)
290 ** **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}
291 ** **Status codes:**
292 *** 200: If the request was successful.
293
294 === /wikis/{wikiName}/query?q~={query}&type~={hql,xwql,lucene,solr}[&distinct~={true,false}]~~[&order~={asc,desc}][&start~=n][&number~=n][&prettyNames~={true,false}][&className~=className] ===
295
296 * **HTTP Method:** GET
297 ** **Media types:**
298 *** application/xml (SearchResults element)
299 ** **Description:** Allow to execute HQL, XWQL, Lucene or SOLR queries on the given {wikiName}. The //q// parameter contains the corresponding query. See [[HQL Query Examples in Velocity>>platform:DevGuide.velocityHqlExamples]], [[XWiki Query Language Specification>>dev:Design.XWiki Query Language Specification]], [[Lucene Plugin>>extensions:Extension.Lucene Plugin]] and [[SOLR query API>>extensions:Extension.Solr Search Query API]] examples of the queries that can be specified in this parameter. If type is //hql// and //className// is specified, the result will also contain the data for the first object of the corresponding class.
300 ** **Status codes:**
301 *** 200: If the request was successful.
302
303 === /wikimanager (This resource is only available when using the [[multi-wiki>>extensions:Extension.Wiki Application]] feature) ===
304
305 * **HTTP Method:** POST
306 ** **Accepted Media types:**
307 *** application/xml (Wiki element)
308 ** **Media types:**
309 *** application/xml (Wiki element)
310 ** **Query parameters**
311 *** template - the wiki template to be used for initializing the wiki.
312 *** history={RESET/REPLACE/ADD} - history importing
313 ** **Description:** create a new wiki.
314 ** **Status codes:**
315 *** 200: If the request was successful.
316
317 == Space resources ==
318
319 === /wikis/{wikiName}/spaces[?start~=offset&number~=n] ===
320
321 * **HTTP Method:** GET
322 ** **Media types:**
323 *** application/xml (Spaces element)
324 ** **Description:** Retrieves the list of spaces available in the {wikiName} wiki.
325 ** **Status codes:**
326 *** 200: If the request was successful.
327
328 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/search?q~={keywords}~[~[&scope~={name,content,title,objects}...]&number~=n] ===
329
330 * **HTTP Method:** GET
331 ** **Media types:**
332 *** application/xml (Search results element)
333 ** **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}
334 ** **Status codes:**
335 *** 200: If the request was successful.
336 *** 401: If the user is not authorized.
337
338 == Page resources ==
339
340 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages[?start~=offset&number~=n] ===
341
342 * **HTTP Method:** GET
343 ** **Media types:**
344 *** application/xml (Pages element)
345 ** **Description:** The list of pages in the space {spaceName}
346 ** **Status codes:**
347 *** 200: If the request was successful.
348 *** 401: If the user is not authorized.
349
350 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages/{pageName}[?prettyNames~={true,false}&objects~={true,false}&class~={true,false}&attachments~={true,false}] ===
351
352 * **HTTP Method:** GET
353 ** **Media types:**
354 *** application/xml (Page element)
355 ** **Query parameters**
356 *** ##prettyNames##: also return the pretty name for various document information (like the author display name, etc). Disabled by default.
357 *** ##objects##: //[since 7.3M1]// also return the objects. Disabled by default.
358 *** ##class##: //[since 7.3M1]// also return the class. Disabled by default.
359 *** ##attachments##: //[since 7.3M1]// also return the attachments metadatas. Disabled by default.
360 ** **Description:**
361 ** **Status codes:**
362 *** 200: If the request was successful.
363 *** 401: If the user is not authorized.
364
365 \\
366
367 * **HTTP Method:** PUT
368 ** **Accepted Media types:**
369 *** application/xml (Page element)
370 *** text/plain (Only page content)
371 *** application/x-www-form-urlencoded (allowed field names: title, parent, hidden //[since 7.3]//, content)
372 ** **Media types:**
373 *** application/xml (Page element)
374 ** **Description:** Create or updates a page.
375 ** **Status codes:**
376 *** 201: If the page was created.
377 *** 202: If the page was updated.
378 *** 304: If the page was not modified.
379 *** 401: If the user is not authorized.
380
381 \\
382
383 * **HTTP Method:** DELETE
384 ** **Media types:**
385 *** application/xml (Page element)
386 ** **Description:** Delete the page.
387 ** **Status codes:**
388 *** 204: If the request was successful.
389 *** 401: If the user is not authorized.
390
391 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages/{pageName}/history[?start~=offset&number~=n] ===
392
393 * **HTTP Method:** GET
394 ** **Media types:**
395 *** application/xml (History element)
396 ** **Description:** The list of all the versions of the given page.
397 ** **Status codes:**
398 *** 200: If the request was successful.
399 *** 401: If the user is not authorized.
400
401 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages/{pageName}/history/{version} ===
402
403 * **HTTP Method:** GET
404 ** **Media types:**
405 *** application/xml (Page element)
406 ** **Description:** The page at version {version}
407 ** **Status codes:**
408 *** 200: If the request was successful.
409 *** 401: If the user is not authorized.
410
411 ==== /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages/{pageName}/translations[?start~=offset&number~=n] ====
412
413 * **HTTP Method:** GET
414 ** **Media types:**
415 *** application/xml (Translations element)
416 ** **Description:** The list of available translation for the page
417 ** **Status codes:**
418 *** 200: If the request was successful.
419 *** 401: If the user is not authorized.
420
421 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages/{pageName}/translations/{language} ===
422
423 * **HTTP Method:** GET
424 ** **Media types:**
425 *** application/xml (Page element)
426 ** **Description:** The page at in the given {language}.
427 ** **Status codes:**
428 *** 200: If the request was successful.
429 *** 401: If the user is not authorized.
430
431 \\
432
433 * **HTTP Method:** PUT
434 ** **Accepted Media types:**
435 *** application/xml (Page element)
436 *** text/plain (Only page content)
437 *** application/x-www-form-urlencoded (allowed field names: title, parent, content)
438 ** **Media types:**
439 *** application/xml (Page element)
440 ** **Description:** Create or updates a page translation.
441 ** **Status codes:**
442 *** 201: If the page was created.
443 *** 202: If the page was updated.
444 *** 304: If the page was not modified.
445 *** 401: If the user is not authorized.
446
447 \\
448
449 * **HTTP Method:** DELETE
450 ** **Media types:**
451 *** application/xml (Page element)
452 ** **Description:** Delete the page translation.
453 ** **Status codes:**
454 *** 204: If the request was successful.
455 *** 401: If the user is not authorized.
456
457 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages/{pageName}/translations/{language}/history ===
458
459 * **HTTP Method:** GET
460 ** **Media types:**
461 *** application/xml (History element)
462 ** **Description:** The list of all the available revisions of the page in a given {language}.
463 ** **Status codes:**
464 *** 200: If the request was successful.
465 *** 401: If the user is not authorized.
466
467 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages/{pageName}/translations/{lang}/history/{version} ===
468
469 * **HTTP Method:** GET
470 ** **Media types:**
471 *** application/xml (Page element)
472 ** **Description:** A page at a given {version} in a given {language}.
473 ** **Status codes:**
474 *** 200: If the request was successful.
475 *** 401: If the user is not authorized.
476
477 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages/{pageName}/children ===
478
479 * **HTTP Method:** GET
480 ** **Media types:**
481 *** application/xml (Pages element)
482 ** **Description:** The list of the children of a given page.
483 ** **Status codes:**
484 *** 200: If the request was successful.
485 *** 401: If the user is not authorized.
486
487 === /wikis/{wikiName}/pages[?name~=paneName&space~=spaceName&author~=authorName] ===
488
489 * **HTTP Method:** GET
490 ** **Media types:**
491 *** application/xml (Pages element)
492 ** **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.
493 ** **Status codes:**
494 *** 200: If the request was successful.
495 *** 401: If the user is not authorized.
496
497 == Tag resources ==
498
499 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages/{pageName}/tags ===
500
501 * **HTTP Method:** GET
502 ** **Media types:**
503 *** application/xml (Tags element)
504 ** **Description:** List page tags.
505 ** **Status codes:**
506 *** 200: If the request was successful.
507 *** 401: If the user is not authorized.
508
509 \\
510
511 * **HTTP Method:** PUT
512 ** **Accepted Media types:**
513 *** application/xml (Tag element)
514 *** text/plain
515 *** application/x-www-form-urlencoded (allowed field names: tag)
516 ** **Media types:**
517 *** application/xml (Tags element)
518 ** **Description:** Add a tag to the page.
519 ** **Status codes:**
520 *** 202: If the request was successful.
521 *** 401: If the user is not authorized.
522
523 === /wikis/{wikiName}/tags ===
524
525 * **HTTP Method:** GET
526 ** **Media types:**
527 *** application/xml (Tags element)
528 ** **Description:** The list of all available tags
529 ** **Status codes:**
530 *** 200: If the request was successful.
531 *** 401: If the user is not authorized.
532
533 === /wikis/{wikiName}/tags/{tag1}[,{tag2},{tag3}...][?start~=offset&number~=n] ===
534
535 * **HTTP Method:** GET
536 ** **Media types:**
537 *** application/xml (Pages element)
538 ** **Description:** The list of pages having the specified tags.
539 ** **Status codes:**
540 *** 200: If the request was successful.
541 *** 401: If the user is not authorized.
542
543 == Comments resources ==
544
545 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages/{pageName}/comments[?start~=offset&number~=n] ===
546
547 * **HTTP Method:** GET
548 ** **Media types:**
549 *** application/xml (Comments element)
550 ** **Description:** The list of comments on a given page.
551 ** **Status codes:**
552 *** 200: If the request was successful.
553 *** 401: If the user is not authorized.
554
555 \\
556
557 * **HTTP Method:** POST
558 ** **Accepted Media types:**
559 *** application/xml (Comment element)
560 *** text/plain
561 *** application/x-www-form-urlencoded - allowed field names: ##text##, ##replyTo## (object number of the replied comment, since XE 2.3)
562 ** **Media types:**
563 *** application/xml (Comment element)
564 ** **Description:** Create a comment on the given page.
565 ** **Status codes:**
566 *** 201: If the comment was created. (The Location header will contain the URI where the comment has been created.)
567 *** 401: If the user is not authorized.
568
569 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages/{pageName}/comments/{commentId} ===
570
571 * **HTTP Method:** GET
572 ** **Media types:**
573 *** application/xml (Comment element)
574 ** **Description:** A specific comment on a page
575 ** **Status codes:**
576 *** 200: If the request was successful.
577 *** 401: If the user is not authorized.
578
579 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages/{pageName}/history/{version}/comments ===
580
581 * **HTTP Method:** GET
582 ** **Media types:**
583 *** application/xml (Comments element)
584 ** **Description:** The list of comments at a specific page {version}.
585 ** **Status codes:**
586 *** 200: If the request was successful.
587 *** 401: If the user is not authorized.
588
589 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages/{pageName}/history/{version}/comments/{commentId} ===
590
591 * **HTTP Method:** GET
592 ** **Media types:**
593 *** application/xml (Comment element)
594 ** **Description:** A comment at a specific page {version}.
595 ** **Status codes:**
596 *** 200: If the request was successful.
597 *** 401: If the user is not authorized.
598
599 == Attachments resources ==
600
601 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages/{pageName}/attachments[?start~=offset&number~=n] ===
602
603 * **HTTP Method:** GET
604 ** **Media types:**
605 *** application/xml (Attachments element)
606 ** **Description:** The list of attachments of a given page.
607 ** **Status codes:**
608 *** 200: If the request was successful.
609 *** 401: If the user is not authorized.
610
611 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages/{pageName}/attachments/{attachmentName} ===
612
613 * **HTTP Method:** GET
614 ** **Media types:**
615 *** The same of the attachment media type.
616 ** **Description:** The attachment identified by {attachmentName} on a given page.
617 ** **Status codes:**
618 *** 200: If the request was successful.
619 *** 401: If the user is not authorized.
620
621 \\
622
623 * **HTTP Method:** PUT
624 ** **Accepted media types:**
625 *** **/**
626 ** **Media types:**
627 *** application/xml (AttachmentSummary element)
628 ** **Description:** Create an attachment identified by {attachmentName} on a given page.
629 ** **Status codes:**
630 *** 201: If the attachment was created.
631 *** 202: If the attachment was updated.
632 *** 401: If the user is not authorized.
633
634 \\
635
636 * **HTTP Method:** DELETE
637 ** **Media types:**
638 ** **Description:** Delete the attachment identified by {attachmentName} on a given page.
639 ** **Status codes:**
640 *** 204: If the attachment was deleted.
641 *** 401: If the user is not authorized.
642
643 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages/{pageName}/history/{version}/attachments[?start~=offset&number~=n] ===
644
645 * **HTTP Method:** GET
646 ** **Media types:**
647 *** application/xml (Attachments element)
648 ** **Description:** The list of attachments at a given page {version}.
649 ** **Status codes:**
650 *** 200: If the request was successful.
651 *** 401: If the user is not authorized.
652
653 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages/{pageName}/history/{version}/attachments/{attachmentName} ===
654
655 * **HTTP Method:** GET
656 ** **Media types:**
657 *** The same of the attachment media type.
658 ** **Description:** The attachment identified by {attachmentName} on a given page {version}.
659 ** **Status codes:**
660 *** 200: If the request was successful.
661 *** 401: If the user is not authorized.
662
663 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages/{pageName}/attachments/{attachmentName}/history ===
664
665 * **HTTP Method:** GET
666 ** **Media types:**
667 *** application/xml (Attachments element)
668 ** **Description:** The list of available version for the {attachmentName}
669 ** **Status codes:**
670 *** 200: If the request was successful.
671 *** 401: If the user is not authorized.
672
673 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages/{pageName}/attachments/{attachmentName}/history/{version} ===
674
675 * **HTTP Method:** GET
676 ** **Media types:**
677 *** The same of the attachment media type.
678 ** **Description:** The {attachmentName} at a given {version}
679 ** **Status codes:**
680 *** 200: If the request was successful.
681 *** 401: If the user is not authorized.
682
683 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/attachments[?name~=attachmentName&page~=pageName&author~=authorName&types~=attachmentTypeList&start~=offset&number~=n] ===
684
685 * **HTTP Method:** GET
686 ** **Media types:**
687 *** application/xml (Attachments element)
688 ** **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.
689 ** **Status codes:**
690 *** 200: If the request was successful.
691 *** 401: If the user is not authorized.
692
693 === /wikis/{wikiName}/attachments[?name~=attachmentName&page~=pageName&space~=spaceName&author~=authorName&types~=attachmentTypeList&start~=offset&number~=n] ===
694
695 * **HTTP Method:** GET
696 ** **Media types:**
697 *** application/xml (Attachments element)
698 ** **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.
699 ** **Status codes:**
700 *** 200: If the request was successful.
701 *** 401: If the user is not authorized.
702
703 == Object resources ==
704
705 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages/{pageName}/objects[?start~=offset&number~=n] ===
706
707 * **HTTP Method:** GET
708 ** **Media types:**
709 *** application/xml (Objects element)
710 ** **Description:** The list of objects associated to a page.
711 ** **Status codes:**
712 *** 200: If the request was successful.
713 *** 401: If the user is not authorized.
714
715 \\
716
717 * **HTTP Method:** POST
718 ** **Accepted media types:**
719 *** application/xml (Object element)
720 *** application/x-www-form-urlencoded (a set of property#name=value pairs representing properties and a field className)
721 **** e.g. {{code language="none"}}className=XWiki.XWikiUsers&property#first_name=John&property#last_name=Doe{{/code}}
722 ** **Media types:**
723 *** application/xml (Object element)
724 ** **Description:** Create a new object.
725 ** **Status codes:**
726 *** 201: If the object was created (The Location header will contain the URI associated to the newly created object).
727 *** 401: If the user is not authorized.
728
729 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages/{pageName}/objects/{className}[?start~=offset&number~=n] ===
730
731 * **HTTP Method:** GET
732 ** **Media types:**
733 *** application/xml (Objects element)
734 ** **Description:** The list of objects of a given {className} associated to a page.
735 ** **Status codes:**
736 *** 200: If the request was successful.
737 *** 401: If the user is not authorized.
738
739 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages/{pageName}/objects/{className}/{objectNumber} ===
740
741 * **HTTP Method:** GET
742 ** **Media types:**
743 *** application/xml (Object element)
744 ** **Description:** The object of type {className} identified by {objectNumber} associated to the given page.
745 ** **Status codes:**
746 *** 200: If the request was successful.
747 *** 401: If the user is not authorized.
748
749 \\
750
751 * **HTTP Method:** PUT
752 ** **Accepted media types:**
753 *** application/xml (Object element)
754 *** application/x-www-form-urlencoded (a set of property#name=value pairs representing properties)
755 ** **Media types:**
756 *** application/xml (Object element)
757 ** **Description:** Modify the object properties.
758 ** **Status codes:**
759 *** 202: If the object was updated.
760 *** 401: If the user is not authorized.
761
762 \\
763
764 * **HTTP Method:** DELETE
765 ** **Media types:**
766 ** **Description:** Delete the object.
767 ** **Status codes:**
768 *** 204: If the object was deleted.
769 *** 401: If the user is not authorized.
770
771 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages/{pageName}/objects/{className}/{objectNumber}/properties ===
772
773 * **HTTP Method:** GET
774 ** **Media types:**
775 *** application/xml (Properties element)
776 ** **Description:** The properties of the object of type {className} identified by {objectNumber} associated to the given page.
777 ** **Status codes:**
778 *** 200: If the request was successful.
779 *** 401: If the user is not authorized.
780
781 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages/{pageName}/objects/{className}/{objectNumber}/properties/{propertyName} ===
782
783 * **HTTP Method:** GET
784 ** **Media types:**
785 *** application/xml (Properties element)
786 ** **Description:** The property {propertyname} of the object of type {className} identified by {objectNumber} associated to the given page.
787 ** **Status codes:**
788 *** 200: If the request was successful.
789 *** 401: If the user is not authorized.
790
791 \\
792
793 * **HTTP Method:** PUT
794 ** **Accepted media types:**
795 *** application/xml (Property element)
796 *** text/plain
797 *** application/x-www-form-urlencoded (a field property#name=value pairs representing a property)
798 ** **Media types:**
799 *** application/xml (Property element)
800 ** **Description:** Modify the object properties.
801 ** **Status codes:**
802 *** 202: If the object was updated.
803 *** 401: If the user is not authorized.
804
805 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages/{pageName}/history/{version}/objects[?start~=offset&number~=n] ===
806
807 * **HTTP Method:** GET
808 ** **Media types:**
809 *** application/xml (Objects element)
810 ** **Description:** The list of objects associated to a page at a given {version}.
811 ** **Status codes:**
812 *** 200: If the request was successful.
813 *** 401: If the user is not authorized.
814
815 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages/{pageName}/history/{version}/objects/{className}/{objectNumber} ===
816
817 * **HTTP Method:** GET
818 ** **Media types:**
819 *** application/xml (Object element)
820 ** **Description:** The object of type {className} identified by {objectNumber} associated to the given page at a given {version}.
821 ** **Status codes:**
822 *** 200: If the request was successful.
823 *** 401: If the user is not authorized.
824
825 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages/{pageName}/history/{version}/objects/{className}/{objectNumber}/properties ===
826
827 * **HTTP Method:** GET
828 ** **Media types:**
829 *** application/xml (Properties element)
830 ** **Description:** The properties of the object of type {className} identified by {objectNumber} associated to the given page at a given {version}.
831 ** **Status codes:**
832 *** 200: If the request was successful.
833 *** 401: If the user is not authorized.
834
835 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages/{pageName}/history/{version}/objects/{className}/{objectNumber}/properties/{propertyName} ===
836
837 * **HTTP Method:** GET
838 ** **Media types:**
839 *** application/xml (Properties element)
840 ** **Description:** The property {propertyname} of the object of type {className} identified by {objectNumber} associated to the given page at a given {version}.
841 ** **Status codes:**
842 *** 200: If the request was successful.
843 *** 401: If the user is not authorized.
844
845 === /wikis/{wikiName}/class/{className}/objects ===
846
847 * **HTTP Method:** GET
848 ** **Media types:**
849 *** application/xml (Objects element)
850 ** **Description:** The list of all the objects of a given {className}.
851 ** **Status codes:**
852 *** 200: If the request was successful.
853 *** 401: If the user is not authorized.
854
855 == Class resources ==
856
857 === /wikis/{wikiName}/classes[?start~=offset&number~=n] ===
858
859 * **HTTP Method:** GET
860 ** **Media types:**
861 *** application/xml (Classes element)
862 ** **Description:** The list of all the classes defined in the wiki {wikiName}
863 ** **Status codes:**
864 *** 200: If the request was successful.
865 *** 401: If the user is not authorized.
866
867 === /wikis/{wikiName}/classes/{className} ===
868
869 * **HTTP Method:** GET
870 ** **Media types:**
871 *** application/xml (Class element)
872 ** **Description:** The {className} definition
873 ** **Status codes:**
874 *** 200: If the request was successful.
875 *** 401: If the user is not authorized.
876
877 === /wikis/{wikiName}/classes/{className}/properties ===
878
879 * **HTTP Method:** GET
880 ** **Media types:**
881 *** application/xml (Properties element)
882 ** **Description:** The properties of the class {className}.
883 ** **Status codes:**
884 *** 200: If the request was successful.
885 *** 401: If the user is not authorized.
886
887 === /wikis/{wikiName}/classes/{className}/properties/{property} ===
888
889 * **HTTP Method:** GET
890 ** **Media types:**
891 *** application/xml (Property element)
892 ** **Description:** The property {property} of the class {className}.
893 ** **Status codes:**
894 *** 200: If the request was successful.
895 *** 401: If the user is not authorized.
896
897 == Job resources ==
898
899 A job is identified by an ID (##jobId##) which is a list of strings. In the REST URL, you have to represent the ID with a list of strings separated by ##/##. (eg: ##refactoring/delete/11451##).
900
901 === /jobstatus/{jobId} {{info}}Since 7.2M3{{/info}} ===
902
903 Request parameters:
904
905 |=Name|=Required|=Values|=Default|=Description|=Version
906 |##request##|no|##true~|false##|##false##|Return also the job request|9.1RC1
907 |##progress##|no|##true~|false##|##true##|Return also the job progress|9.1RC1
908 |##log##|no|##true~|false##|##false##|Return also the job log|9.1RC1
909 |##log_fromLevel##|no|##error~|warn~|info~|debug~|trace##||Indicate the level from which to return logs|9.1RC1
910
911 * **HTTP Method:** GET
912 ** **Media types:**
913 *** application/xml (JobStatus element)
914 ** **Description:** status of a job
915 ** **Status codes:**
916 *** 200: If the request was successful.
917 *** 404: If the job status has not been found
918
919 === /joblog/{jobId} {{info}}Since 7.2M3{{/info}} ===
920
921 Request parameters:
922
923 |=Name|=Required|=Values|=Default|=Description|=Version
924 |##level##|no|##error~|warn~|info~|debug~|trace##||Indicate the exact level for which to return logs|7.2M3
925 |##fromLevel##|no|##error~|warn~|info~|debug~|trace##||Indicate the level from which to return logs|7.2M3
926
927 * **HTTP Method:** GET
928 ** **Media types:**
929 *** application/xml (JobLog element)
930 ** **Description:** log of a job
931 ** **Status codes:**
932 *** 200: If the request was successful.
933 *** 404: If the job status has not been found
934
935 === /jobs {{info}}Since 9.1RC1{{/info}} ===
936
937 Request parameters:
938
939 |=Name|=Required|=Values|=Default|=Description|=Version
940 |##jobType##|yes|||The type of the job to pass to the Job Executor|9.1RC1
941 |##async##|no|##true~|false##|##true##|If false, return the response only when the job is done|9.1RC1
942
943 Since 9.2RC1 jobs started trough the REST API automatically get their runtime context injected with the following REST HTTP request context properties:
944
945 * current wiki
946 * current user
947 * request URL and parameters
948
949 Since 9.7RC1 failing jobs with ##async=false## return an error 500.
950
951 * **HTTP Method:** PUT
952 ** **Accepted Media types:**
953 *** application/xml (JobRequest element)
954 *** application/json (JobRequest element)
955 ** **Media types:**
956 *** application/xml (JobStatus element)
957 *** application/json (JobStatus element)
958 ** **Description:** Start a new job synchronously or asynchronously
959 ** **Status codes:**
960 *** 201: If the page was created.
961 *** 202: If the page was updated.
962 *** 401: If the user is not authorized.
963
964 == Other resources ==
965
966 === /wikis/{wikiName}/modifications[?start~=offset&number~=n&date~=t] ===
967
968 * **HTTP Method:** GET
969 ** **Media types:**
970 *** application/xml (Modifications element)
971 ** **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)
972 ** **Status codes:**
973 *** 200: If the request was successful.
974 *** 401: If the user is not authorized.
975
976 = Custom resources =
977
978 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).
979
980 {{code language="java"}}
981 package org.xwiki.contrib.rest;
982
983 import javax.ws.rs.DefaultValue;
984 import javax.ws.rs.GET;
985 import javax.ws.rs.Path;
986
987 import org.xwiki.component.annotation.Component;
988 import org.xwiki.rest.XWikiResource;
989
990 @Component("org.xwiki.contrib.rest.HelloWordResource")
991 @Path("/myresources/{myresourcename}")
992 class HelloWorldResource extends XWikiResource {
993 @GET
994 public String get(@PathParam("myresourcename") @DefaultValue("world") String myresourcename)
995 {
996 return "Hello " + myresourcename;
997 }
998 }
999 {{/code}}
1000
1001 The name of the component has to be the class FQN.
1002
1003 You can find more examples on [[this page>>https://github.com/xwiki/xwiki-platform/tree/master/xwiki-platform-core/xwiki-platform-rest/xwiki-platform-rest-server/src/main/java/org/xwiki/rest]].
1004
1005 Starting from release 4.3M2, the RESTful API modules have been refactored so that now resource declarations are available in a separate module.
1006 This means that all the information about resources, i.e., URI Paths, supported methods, query parameters, and so on, are available to module developers without having to include the big REST Server module.
1007
1008 Clients willing to access/use the REST API can then declare a dependency on xwiki-platform-rest-api and have all this information available for interacting with it. There are two use cases for this:
1009
1010 * Another platform module that wants to generate responses with links to existing resources.
1011 * HTTP clients that wants to make requests to the RESTful API.
1012
1013 The xwiki-platform-rest-api module can be also seen as an authoritative reference for the REST API.
1014
1015 = Generate a REST URL for a resource =
1016
1017 If you need to generate a REST URL as String for a resource inside a script, you can use the REST script services:
1018
1019 {{code language="velocity"}}
1020 ## Return a relative URL String unless the reference wiki is different from the current wiki
1021 $services.rest.url($entityReference)
1022
1023 ## Force returning an external form URL String, false as second parameter would have the same effect that the previous call
1024 $services.rest.url($entityReference, true)
1025 {{/code}}
1026
1027 Where ##$entityReference## could be:
1028
1029 * a ##DocumentReference##
1030 * a ##SpaceReference##
1031
1032 We plan to add more supported entities in the future (ObjectReference, ClassReference, etc...).
1033
1034 = Using the RESTful API =
1035
1036 == Tutorial ==
1037
1038 See [[this tutorial>>http://blog.fabio.mancinelli.me/2011/03/07/XWikis_RESTful_API.html]] by Fabio Mancinelli.
1039
1040 == Creating an XWiki Object ==
1041
1042 In this example we will use the [[curl>>http://curl.haxx.se/]] utility as the HTTP client.
1043
1044 Imagine that you want to create on the page Test.Test a new object of the class XWiki.TestClass, supposing that the class has a property called ##text##.
1045
1046 So, on the command line, you have to do the following:
1047
1048 {{code}}
1049 $ curl -u Admin:admin
1050 -X POST
1051 -H "Content-type: application/xml"
1052 -H "Accept: application/xml"
1053 -d "@test.xml"
1054 http://localhost/xwiki/rest/wikis/xwiki/spaces/Test/pages/Test/objects
1055 {{/code}}
1056
1057 where ##test.xml## is:
1058
1059 {{code language="xml"}}
1060 <object xmlns="http://www.xwiki.org">
1061 <className>XWiki.TestClass</className>
1062 <property name="text">
1063 <value>Whatever you want to put here</value>
1064 </property>
1065 </object>
1066 {{/code}}
1067
1068 Alternatively you can use the less verbose ##application/x-www-form-urlencoded format##:
1069
1070 {{code}}
1071 $ curl -u Admin:admin
1072 -X POST
1073 -H "Content-type: application/x-www-form-urlencoded"
1074 -H "Accept: application/xml"
1075 -d "@test.txt"
1076 http://localhost/xwiki/rest/wikis/xwiki/spaces/Test/pages/Test/objects
1077 {{/code}}
1078
1079 where ##test.txt## contains something like:
1080
1081 {{code}}
1082 className=XWiki.TestClass&property#test=Whatever+you+want
1083 {{/code}}
1084
1085 Or, better, you can use directly curl to specify these parameters
1086 using multiple ##-d## switches:
1087
1088 {{code}}
1089 $ curl -u Admin:admin
1090 -X POST -H "Content-type: application/x-www-form-urlencoded"
1091 -H "Accept: application/xml"
1092 -d "className=XWiki.TestClass"
1093 -d "property#test=Whatever you want"
1094 http://localhost/xwiki/rest/wikis/xwiki/spaces/Test/pages/Test/objects
1095 {{/code}}
1096
1097 The advantage of the second approach is that curl will take care of url-encode your content, while if you send a file you are responsible for this.
1098
1099 === Remarks: ===
1100
1101 * In the ##application/x-www-form-urlencoded## format the "property#" is a standard immutable prefix that is used to distinguish attributes referring to property values from the attributes referring to the object. For example if we had ##className=XYZ&Text=FOO## we would have had an ambiguity on ##className## because we couldn't understand if ##className## is a property of the object to be set to XYZ or an attribute that describes the object itself (i.e., its metadata like the ##className##). By having the ##property### prefix this ambiguity is resolved.
1102
1103 * The information you get back when you retrieve an object (i.e., all
1104 the ##<attribute>## elements) are useful when clients need to understand the type of data contained in an object (e.g., when they want to display it). They are not necessary when creating an object because the system already has this information. That's why the XML to be sent is smaller. Actually the only information needed is the ##<className>## and a set of ##<property name="..."><value>## elements.
1105
1106 * How do you know what kind of information you can send with the XML? You can discover it by using the class description URI. If you go to ##http:~/~/localhost:8080/xwiki/rest/wikis/xwiki/classes ## you will get a list of all the classes defined in the Wiki. By looking at this you will understand what are the properties defined by each class, their types and attributes. In that way you will know what you're allowed to put in the ##<property><value>## elements of the XML you send.
1107
1108 == Formats of files ==
1109
1110 A XSD schema exists for XWiki (look [[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]] for the source).
1111
1112 However, you may not know exactly how to write the XML files to use when using the PUT method. First thing to know, you may try to get examples by using ##GET## HTTP request to the REST service using cURL or similar tools.
1113
1114 But in order to help you, you'll find below the different formats that you can use. Note that the following XML files are exhaustive files but not all the elements are required.
1115
1116 === Example of a file for a ##wiki## ===
1117
1118 {{code language="xml"}}
1119 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
1120 <wiki xmlns="http://www.xwiki.org">
1121 <id>xwiki</id>
1122 <name>xwiki</name>
1123 <description>Some description of the wiki</description>
1124 <owner>Admin</owner>
1125 </wiki>
1126 {{/code}}
1127
1128 === Example of a file for a ##space## ===
1129
1130 {{code language="xml"}}
1131 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
1132 <space xmlns="http://www.xwiki.org">
1133 <id>xwiki:Main</id>
1134 <wiki>xwiki</wiki>
1135 <name>Main</name>
1136 <home>xwiki:Main.WebHome</home>
1137 <xwikiRelativeUrl>http://localhost:8080/xwiki/bin/view/Main/</xwikiRelativeUrl>
1138 <xwikiAbsoluteUrl>http://localhost:8080/xwiki/bin/view/Main/</xwikiAbsoluteUrl>
1139 </space>
1140 {{/code}}
1141
1142 === Example of a file for a ##page## ===
1143
1144 {{code language="xml"}}
1145 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
1146 <page xmlns="http://www.xwiki.org">
1147 <id>xwiki:Main.WebHome</id>
1148 <fullName>Main.WebHome</fullName>
1149 <wiki>xwiki</wiki>
1150 <space>Main</space>
1151 <name>WebHome</name>
1152 <title>Home</title>
1153 <parent/>
1154 <parentId/>
1155 <version>1.1</version>
1156 <author>XWiki.Admin</author>
1157 <authorName>Administrator</authorName>
1158 <xwikiRelativeUrl>http://localhost:8080/xwiki/bin/view/Main/</xwikiRelativeUrl>
1159 <xwikiAbsoluteUrl>http://localhost:8080/xwiki/bin/view/Main/</xwikiAbsoluteUrl>
1160 <translations/>
1161 <syntax>xwiki/2.0</syntax>
1162 <language/>
1163 <majorVersion>1</majorVersion>
1164 <minorVersion>1</minorVersion>
1165 <hidden>false</hidden>
1166 <created>2009-09-09T02:00:00+02:00</created>
1167 <creator>XWiki.Admin</creator>
1168 <creatorName>Administrator</creatorName>
1169 <modified>2015-10-29T11:19:02+01:00</modified>
1170 <modifier>XWiki.Admin</modifier>
1171 <modifierName>Administrator</modifierName>
1172 <comment>Imported from XAR</comment>
1173 <content>{{include reference="Dashboard.WebHome" context="new"/}}</content>
1174 </page>
1175 {{/code}}
1176
1177 === Example of a file for a ##tag## ===
1178
1179 {{code language="xml"}}
1180 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
1181 <tags xmlns="http://www.xwiki.org">
1182 <tag name="food"></tag>
1183 </tags>
1184 {{/code}}
1185
1186 === Example of a file for a ##comment## ===
1187
1188 {{code language="xml"}}
1189 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
1190 <comments xmlns="http://www.xwiki.org">
1191 <comment>
1192 <id>0</id>
1193 <pageId>xwiki:Main.WebHome</pageId>
1194 <author>XWiki.Admin</author>
1195 <authorName>Administrator</authorName>
1196 <date>2015-11-13T18:20:51.936+01:00</date>
1197 <highlight/>
1198 <text>This is a comment</text>
1199 <replyTo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
1200 </comment>
1201 </comments>
1202 {{/code}}
1203
1204 === Example of a file for an ##object## ===
1205
1206 {{code language="xml"}}
1207 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
1208 <object xmlns="http://www.xwiki.org">
1209 <id>xwiki:Main.WebHome:c170a0a8-cc17-41cd-aa1e-6f6faf1d9f28</id>
1210 <guid>c170a0a8-cc17-41cd-aa1e-6f6faf1d9f28</guid>
1211 <pageId>xwiki:Main.WebHome</pageId>
1212 <pageVersion>1.1</pageVersion>
1213 <wiki>xwiki</wiki>
1214 <space>Main</space>
1215 <pageName>WebHome</pageName>
1216 <pageAuthor>XWiki.superadmin</pageAuthor>
1217 <className>XWiki.EditModeClass</className>
1218 <number>0</number>
1219 <headline>edit</headline>
1220 <property name="defaultEditMode" type="String">
1221 <attribute name="name" value="defaultEditMode"/>
1222 <attribute name="prettyName" value="Default Edit Mode"/>
1223 <attribute name="unmodifiable" value="0"/>
1224 <attribute name="disabled" value="0"/>
1225 <attribute name="size" value="15"/>
1226 <attribute name="number" value="1"/>
1227 <value>edit</value>
1228 </property>
1229 </object>
1230 {{/code}}
1231
1232 === Example of a file for a ##property## ===
1233
1234 {{code language="xml"}}
1235 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
1236 <property xmlns="http://www.xwiki.org" name="defaultEditMode" type="String">
1237 <attribute name="name" value="defaultEditMode"/>
1238 <attribute name="prettyName" value="Default Edit Mode"/>
1239 <attribute name="unmodifiable" value="0"/>
1240 <attribute name="disabled" value="0"/>
1241 <attribute name="size" value="15"/>
1242 <attribute name="number" value="1"/>
1243 <value>edit</value>
1244 </property>
1245 {{/code}}
1246
1247 = Examples =
1248
1249 == Getting the list of users ==
1250
1251 Since Users are stored as Objects, you can do a search of the type ##XWiki.XWikiUsers##. For example:
1252
1253 {{code}}
1254 http://<server>/xwiki/rest/wikis/query?q=object:XWiki.XWikiUsers
1255 {{/code}}

Get Connected