Mercurial > p > roundup > code
comparison doc/rest.txt @ 5933:0bac8b9a0ecc
Added curl based examples for retire and restore.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Sat, 19 Oct 2019 09:02:22 -0400 |
| parents | cc6891ea1f01 |
| children | 88316ac61ab0 |
comparison
equal
deleted
inserted
replaced
| 5932:df279b4e34a5 | 5933:0bac8b9a0ecc |
|---|---|
| 1255 | 1255 |
| 1256 | 1256 |
| 1257 >>> import requests | 1257 >>> import requests |
| 1258 >>> u = 'http://user:password@tracker.example.com/demo/rest/data/' | 1258 >>> u = 'http://user:password@tracker.example.com/demo/rest/data/' |
| 1259 >>> s = requests.session() | 1259 >>> s = requests.session() |
| 1260 >>> session.auth = ('admin', 'admin') | |
| 1260 >>> r = s.get(u + 'issue/42/title') | 1261 >>> r = s.get(u + 'issue/42/title') |
| 1261 >>> if r.status_code != 200: | 1262 >>> if r.status_code != 200: |
| 1262 ... print("Failed: %s: %s" % (r.status_code, r.reason)) | 1263 ... print("Failed: %s: %s" % (r.status_code, r.reason)) |
| 1263 ... exit(1) | 1264 ... exit(1) |
| 1264 >>> print (r.json() ['data']['data'] | 1265 >>> print (r.json() ['data']['data'] |
| 1291 Note the addition of headers for: x-requested-with and referer. This | 1292 Note the addition of headers for: x-requested-with and referer. This |
| 1292 allows the request to pass the CSRF protection mechanism. You may need | 1293 allows the request to pass the CSRF protection mechanism. You may need |
| 1293 to add an Origin header if this check is enabled in your tracker's | 1294 to add an Origin header if this check is enabled in your tracker's |
| 1294 config.ini (look for csrf_enforce_header_origin). | 1295 config.ini (look for csrf_enforce_header_origin). |
| 1295 | 1296 |
| 1297 A similar curl based retire example is to use: | |
| 1298 | |
| 1299 curl -s -u admin:admin \ | |
| 1300 -H "Referer: https://tracker.example.com/demo/" \ | |
| 1301 -H "X-requested-with: rest" \ | |
| 1302 -H "Content-Type: application/json" \ | |
| 1303 https://tracker.example.com/demo/rest/data/status/1 | |
| 1304 | |
| 1305 to get the etag manually. Then insert the etag in the If-Match header | |
| 1306 for this retire example:: | |
| 1307 | |
| 1308 curl -s -u admin:admin \ | |
| 1309 -H "Referer: https://tracker.example.com/demo/" \ | |
| 1310 -H "X-requested-with: rest" \ | |
| 1311 -H "Content-Type: application/json" \ | |
| 1312 -H 'If-Match: "a502faf4d6b8e3897c4ecd66b5597571"' \ | |
| 1313 --data-raw '{ "@op":"action", "@action_name": "retire" }'\ | |
| 1314 -X PATCH \ | |
| 1315 https://tracker.example.com/demo/rest/data/status/1 | |
| 1316 | |
| 1317 and restore:: | |
| 1318 | |
| 1319 curl -s -u admin:admin \ | |
| 1320 -H "Referer: https://tracker.example.com/demo/" \ | |
| 1321 -H "X-requested-with: rest" \ | |
| 1322 -H "Content-Type: application/json" \ | |
| 1323 -H 'If-Match: "a502faf4d6b8e3897c4ecd66b5597571"' \ | |
| 1324 --data-raw '{ "@op":"action", "@action_name": "restore" }'\ | |
| 1325 -X PATCH \ | |
| 1326 https://tracker.example.com/demo/rest/data/status/1 | |
| 1327 | |
| 1296 | 1328 |
| 1297 Searches and selection | 1329 Searches and selection |
| 1298 ====================== | 1330 ====================== |
| 1299 | 1331 |
| 1300 One difficult interface issue is selection of items from a long list. | 1332 One difficult interface issue is selection of items from a long list. |
