Mercurial > p > roundup > code
comparison doc/rest.txt @ 5674:6dc4dba1c225
REST: Use If-Match header for incoming requests
| author | Ralf Schlatterbeck <rsc@runtux.com> |
|---|---|
| date | Mon, 25 Mar 2019 21:23:52 +0100 |
| parents | a884698173ea |
| children | 1fa59181ce58 |
comparison
equal
deleted
inserted
replaced
| 5673:6b6bc8d31caf | 5674:6dc4dba1c225 |
|---|---|
| 131 ``DELETE`` method, it retires the item. The ``restore`` action is the | 131 ``DELETE`` method, it retires the item. The ``restore`` action is the |
| 132 inverse of ``retire``, the item is again visible. | 132 inverse of ``retire``, the item is again visible. |
| 133 On success the returned value is the same as the respective ``GET`` | 133 On success the returned value is the same as the respective ``GET`` |
| 134 method. | 134 method. |
| 135 | 135 |
| 136 Note that the ``GET`` method on an item (e.g. ``/data/issue/43``) | |
| 137 returns an ETag in the http header *and* the ``@etag`` value. When | |
| 138 modifying the item via ``PUT`` or ``PATCH`` either a ``If-Match`` header | |
| 139 or an ``@etag`` value in the form have to be provided. | |
| 140 | |
| 136 sample python client | 141 sample python client |
| 137 ==================== | 142 ==================== |
| 138 | 143 |
| 139 The client uses the python ``requests`` library for easier interaction | 144 The client uses the python ``requests`` library for easier interaction |
| 140 with a REST API supporting JSON encoding:: | 145 with a REST API supporting JSON encoding:: |
| 161 >>> r = s.get (u + 'issue/42') | 166 >>> r = s.get (u + 'issue/42') |
| 162 >>> etag = r.headers['ETag'] | 167 >>> etag = r.headers['ETag'] |
| 163 >>> print("ETag: %s" % etag) | 168 >>> print("ETag: %s" % etag) |
| 164 >>> etag = r.json()['data']['@etag'] | 169 >>> etag = r.json()['data']['@etag'] |
| 165 >>> print("@etag: %s" % etag) | 170 >>> print("@etag: %s" % etag) |
| 166 >>> h = dict(ETag = etag) | 171 >>> h = {'If-Match': etag} |
| 167 >>> d = {'@op:'action', '@action_name':'retire'} | 172 >>> d = {'@op:'action', '@action_name':'retire'} |
| 168 >>> r = s.patch(u + 'issue/42', data = d, headers = h) | 173 >>> r = s.patch(u + 'issue/42', data = d, headers = h) |
| 169 >>> print(r.json()) | 174 >>> print(r.json()) |
| 170 >>> d = {'@op:'action', '@action_name':'restore'} | 175 >>> d = {'@op:'action', '@action_name':'restore'} |
| 171 >>> r = s.patch(u + 'issue/42', data = d, headers = h) | 176 >>> r = s.patch(u + 'issue/42', data = d, headers = h) |
