README.rst 2.02 KB
Newer Older
Aurelien Campeas's avatar
Aurelien Campeas committed
1
2
Summary
-------
3

4
5
Controller that gives users rql read/ write capabilities. To have token
authentication, install `cubicweb_signedrequest <https://forge.extranet.logilab.fr/cubicweb/cubes/signedrequest>`_.
6
7
8
9
10
11
12


Sample usage
------------

Users of this service must perform a HTTP POST request to its endpoint,
that is the base url of the CubicWeb application instance appended with
Julien Cristau's avatar
Julien Cristau committed
13
the "rqlio/1.0" url path.
14

15
16
The posted data must use the `application/json` or `multipart/form-data`.
For the `application/json` MIME type, the posted data must contain a list of
17
pairs of the form `(rql_string, rql_args)`, where:
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45

* `rql_string` is any valid RQL query that may contain mapping keys with
  their usual form

* `rql_args` is a dictionary, whose keys are the mapping keys from
  `rql_string`, and the values can be:

  - actual values

  - string references to a previous RQL query's result, with the
    assumption that the referenced RQL query returns a single line and
    single column rset; under such conditions, a string reference
    must be "__rXXX" where `XXX` is the (0-based) index of the RQL query in
    the json-encoded list of queries.

The HTTP request's response (in case where there is no error), is a
json-encoded list.  Its length is the number of RQL queries in the request,
and each element contains the json-encoded result set rows from the
corresponding query.

In case of an error, a json object with a `reason` key will explain the
problem.

Python client example using python-requests::

    import requests
    import json

46
    args = [('INSERT CWUser U: U login %(l)s, U upassword %(p)s',
47
48
49
50
51
52
53
54
            {'l': 'Babar', 'p': 'cubicweb rulez & 42'}),

           ('INSERT CWGroup G: G name "pachyderms"', {}),

           ('SET U in_group G WHERE U eid %(u)s, G eid %(g)s',
            {'u': '__r0', 'g': '__r1'})
           ]

Julien Cristau's avatar
Julien Cristau committed
55
    resp = requests.post('https://myinstance.example.com/rqlio/1.0'),
56
57
58
                         data=json.dumps(args),
                         headers={'Content-Type': 'application/json'})
    assert resp.status_code == 200