Mercurial > p > roundup > code
comparison doc/rest.txt @ 7473:f8b5b0310f88
I think headings are consistant now.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Thu, 08 Jun 2023 09:27:17 -0400 |
| parents | f53de10ea8ea |
| children | a072331c843b |
comparison
equal
deleted
inserted
replaced
| 7472:db58a86aa29d | 7473:f8b5b0310f88 |
|---|---|
| 14 .. contents:: | 14 .. contents:: |
| 15 :local: | 15 :local: |
| 16 :depth: 3 | 16 :depth: 3 |
| 17 | 17 |
| 18 Introduction | 18 Introduction |
| 19 ------------ | 19 ============ |
| 20 | 20 |
| 21 After the last 1.6.0 Release, a REST-API developed in 2015 during a | 21 After the last 1.6.0 Release, a REST-API developed in 2015 during a |
| 22 Google Summer of Code (GSOC) by Chau Nguyen, supervised by Ezio | 22 Google Summer of Code (GSOC) by Chau Nguyen, supervised by Ezio |
| 23 Melotti was integrated. The code was updated by Ralf Schlatterbeck | 23 Melotti was integrated. The code was updated by Ralf Schlatterbeck |
| 24 and John Rouillard to fix some shortcomings and provide the necessary | 24 and John Rouillard to fix some shortcomings and provide the necessary |
| 25 functions for a single page web application, e.g. etag support, | 25 functions for a single page web application, e.g. etag support, |
| 26 pagination, field embedding among others. | 26 pagination, field embedding among others. |
| 27 | 27 |
| 28 Enabling the REST API | 28 Enabling the REST API |
| 29 --------------------- | 29 ===================== |
| 30 | 30 |
| 31 The REST API can be disabled in the ``[web]`` section of ``config.ini`` | 31 The REST API can be disabled in the ``[web]`` section of ``config.ini`` |
| 32 via the variable ``enable_rest`` which is ``yes`` by default. | 32 via the variable ``enable_rest`` which is ``yes`` by default. |
| 33 | 33 |
| 34 Users have to be authorized to use the rest api. The user must have | 34 Users have to be authorized to use the rest api. The user must have |
| 64 explicitly set.) | 64 explicitly set.) |
| 65 | 65 |
| 66 .. _upgrading directions: upgrading.html | 66 .. _upgrading directions: upgrading.html |
| 67 | 67 |
| 68 Preventing CSRF Attacks | 68 Preventing CSRF Attacks |
| 69 ======================= | 69 ----------------------- |
| 70 | 70 |
| 71 Clients should set the header X-REQUESTED-WITH to any value and the | 71 Clients should set the header X-REQUESTED-WITH to any value and the |
| 72 tracker's config.ini should have ``csrf_enforce_header_x-requested-with | 72 tracker's config.ini should have ``csrf_enforce_header_x-requested-with |
| 73 = yes`` or ``required``. | 73 = yes`` or ``required``. |
| 74 | 74 |
| 76 that is not hosted at the same origin as Roundup, you must permit | 76 that is not hosted at the same origin as Roundup, you must permit |
| 77 the origin using the ``allowed_api_origins`` setting in | 77 the origin using the ``allowed_api_origins`` setting in |
| 78 ``config.ini``. | 78 ``config.ini``. |
| 79 | 79 |
| 80 Rate Limiting the API | 80 Rate Limiting the API |
| 81 ===================== | 81 --------------------- |
| 82 | 82 |
| 83 This is a work in progress. This version of roundup includes Rate | 83 This is a work in progress. This version of roundup includes Rate |
| 84 Limiting for the API (which is different from rate limiting login | 84 Limiting for the API (which is different from rate limiting login |
| 85 attempts on the web interface). | 85 attempts on the web interface). |
| 86 | 86 |
| 112 Also the rate limit is a little lossy. Under heavy load, it is | 112 Also the rate limit is a little lossy. Under heavy load, it is |
| 113 possible for it to miscount allowing more than burst count. Errors of | 113 possible for it to miscount allowing more than burst count. Errors of |
| 114 up to 10% have been seen on slower hardware. | 114 up to 10% have been seen on slower hardware. |
| 115 | 115 |
| 116 Client API | 116 Client API |
| 117 ---------- | 117 ========== |
| 118 | 118 |
| 119 The top-level REST url ``/rest/`` will display the current version of | 119 The top-level REST url ``/rest/`` will display the current version of |
| 120 the REST API (Version 1 as of this writing) and some links to relevant | 120 the REST API (Version 1 as of this writing) and some links to relevant |
| 121 endpoints of the API. In the following the ``/rest`` prefix is omitted | 121 endpoints of the API. In the following the ``/rest`` prefix is omitted |
| 122 from relative REST-API links for brevity. | 122 from relative REST-API links for brevity. |
| 123 | 123 |
| 124 Headers | 124 Headers |
| 125 ======= | 125 ------- |
| 126 | 126 |
| 127 If rate limiting is enabled there are 3 "standard" headers: | 127 If rate limiting is enabled there are 3 "standard" headers: |
| 128 | 128 |
| 129 **X-RateLimit-Limit**: Calls allowed per period. | 129 **X-RateLimit-Limit**: Calls allowed per period. |
| 130 | 130 |
| 151 the REST endpoint will be going away. See | 151 the REST endpoint will be going away. See |
| 152 https://www.rfc-editor.org/rfc/rfc8594 for details on this header and | 152 https://www.rfc-editor.org/rfc/rfc8594 for details on this header and |
| 153 the sunset link type. | 153 the sunset link type. |
| 154 | 154 |
| 155 Hyperdb Stats | 155 Hyperdb Stats |
| 156 ============= | 156 ------------- |
| 157 | 157 |
| 158 Adding ``@stats=true`` as a GET query parameter or POST data item will | 158 Adding ``@stats=true`` as a GET query parameter or POST data item will |
| 159 augment the response with an ``@stats`` dictionary. Any value other | 159 augment the response with an ``@stats`` dictionary. Any value other |
| 160 than ``true`` (any case) will disable the ``@stats`` dictionary. When | 160 than ``true`` (any case) will disable the ``@stats`` dictionary. When |
| 161 stats are enabled the response includes an ``@stats`` member and looks | 161 stats are enabled the response includes an ``@stats`` member and looks |
| 178 stats are not shown. The fields are subject to change. An | 178 stats are not shown. The fields are subject to change. An |
| 179 understanding of the code is recommended if you are going to use this | 179 understanding of the code is recommended if you are going to use this |
| 180 info. | 180 info. |
| 181 | 181 |
| 182 Versioning | 182 Versioning |
| 183 ========== | 183 ---------- |
| 184 | 184 |
| 185 Currently there is only one version of the API. Versions are simple | 185 Currently there is only one version of the API. Versions are simple |
| 186 integers. The current version is ``1``. Version selection is | 186 integers. The current version is ``1``. Version selection is |
| 187 implemented in the server using one of three methods: | 187 implemented in the server using one of three methods: |
| 188 | 188 |
| 197 If an explicit version is not provided, the server default is used. | 197 If an explicit version is not provided, the server default is used. |
| 198 The server default is reported by querying the ``/rest/`` endpoint as | 198 The server default is reported by querying the ``/rest/`` endpoint as |
| 199 described above. | 199 described above. |
| 200 | 200 |
| 201 Input Formats | 201 Input Formats |
| 202 ============= | 202 ------------- |
| 203 | 203 |
| 204 For a GET or OPTIONS request, the Content-Type header should | 204 For a GET or OPTIONS request, the Content-Type header should |
| 205 not be sent. | 205 not be sent. |
| 206 | 206 |
| 207 Otherwise Content-Type is allowed to be ``application/json`` or | 207 Otherwise Content-Type is allowed to be ``application/json`` or |
| 208 ``application/x-www-form-urlencoded``. Any other value returns error | 208 ``application/x-www-form-urlencoded``. Any other value returns error |
| 209 code 415. | 209 code 415. |
| 210 | 210 |
| 211 CORS preflight requests | 211 CORS preflight requests |
| 212 ^^^^^^^^^^^^^^^^^^^^^^^ | 212 ~~~~~~~~~~~~~~~~~~~~~~~ |
| 213 | 213 |
| 214 CORS preflight requests are done using the OPTIONS method. They | 214 CORS preflight requests are done using the OPTIONS method. They |
| 215 require that REST be enabled. These requests do not make any changes | 215 require that REST be enabled. These requests do not make any changes |
| 216 or get any information from the database. As a result they are | 216 or get any information from the database. As a result they are |
| 217 available to the anonymous user and any authenticated user. The user | 217 available to the anonymous user and any authenticated user. The user |
| 261 cause a problem. If it is an issue, you can see | 261 cause a problem. If it is an issue, you can see |
| 262 `Creating Custom Rate Limits`_ | 262 `Creating Custom Rate Limits`_ |
| 263 and craft a rate limiter that ignores anonymous OPTIONS requests. | 263 and craft a rate limiter that ignores anonymous OPTIONS requests. |
| 264 | 264 |
| 265 Response Formats | 265 Response Formats |
| 266 ================ | 266 ---------------- |
| 267 | 267 |
| 268 The default response format is json. | 268 The default response format is json. |
| 269 | 269 |
| 270 If you add the ``dicttoxml.py`` module you can request XML formatted | 270 If you add the ``dicttoxml.py`` module you can request XML formatted |
| 271 data using the header ``Accept: application/xml`` in your | 271 data using the header ``Accept: application/xml`` in your |
| 298 extension. You will also get a 406 status if none of the entries in | 298 extension. You will also get a 406 status if none of the entries in |
| 299 the accept header are available or if the accept header is invalid. | 299 the accept header are available or if the accept header is invalid. |
| 300 | 300 |
| 301 | 301 |
| 302 General Guidelines | 302 General Guidelines |
| 303 ================== | 303 ------------------ |
| 304 | 304 |
| 305 Performing a ``GET`` on an item or property of an item will return an | 305 Performing a ``GET`` on an item or property of an item will return an |
| 306 ETag header or an @etag property. This needs to be submitted with | 306 ETag header or an @etag property. This needs to be submitted with |
| 307 ``DELETE``, ``PUT`` and ``PATCH`` operations on the item using an | 307 ``DELETE``, ``PUT`` and ``PATCH`` operations on the item using an |
| 308 ``If-Match`` header or an ``"@etag`` property in the data payload if | 308 ``If-Match`` header or an ``"@etag`` property in the data payload if |
| 403 } | 403 } |
| 404 } | 404 } |
| 405 | 405 |
| 406 | 406 |
| 407 Special Endpoints | 407 Special Endpoints |
| 408 ================= | 408 ----------------- |
| 409 | 409 |
| 410 There are a few special endpoints that provide some additional data. | 410 There are a few special endpoints that provide some additional data. |
| 411 Tracker administrators can add new endpoints. See | 411 Tracker administrators can add new endpoints. See |
| 412 "Programming the REST API"_ below. | 412 "Programming the REST API"_ below. |
| 413 | 413 |
| 414 /summary | 414 /summary |
| 415 ^^^^^^^^ | 415 ~~~~~~~~ |
| 416 | 416 |
| 417 A Summary page can be reached via ``/summary`` via the ``GET`` method. | 417 A Summary page can be reached via ``/summary`` via the ``GET`` method. |
| 418 This is currently hard-coded for the standard tracker schema shipped | 418 This is currently hard-coded for the standard tracker schema shipped |
| 419 with roundup and will display a summary of open issues. | 419 with roundup and will display a summary of open issues. |
| 420 | 420 |
| 421 /data | 421 /data |
| 422 ^^^^^ | 422 ~~~~~ |
| 423 | 423 |
| 424 This is the primary entry point for data from the tracker. | 424 This is the primary entry point for data from the tracker. |
| 425 | 425 |
| 426 The ``/data`` link will display a set of classes of the tracker. All | 426 The ``/data`` link will display a set of classes of the tracker. All |
| 427 classes can be reached via ``/data/<classname>`` where ``<classname>`` | 427 classes can be reached via ``/data/<classname>`` where ``<classname>`` |
| 437 dictionary with the entry ``data`` referring to the returned data. | 437 dictionary with the entry ``data`` referring to the returned data. |
| 438 | 438 |
| 439 Details are in the sections below. | 439 Details are in the sections below. |
| 440 | 440 |
| 441 /data/\ *class* Collection | 441 /data/\ *class* Collection |
| 442 ========================== | 442 -------------------------- |
| 443 | 443 |
| 444 When performing the ``GET`` method on a class (e.g. ``/data/issue``), | 444 When performing the ``GET`` method on a class (e.g. ``/data/issue``), |
| 445 the ``data`` object includes the number of items available in | 445 the ``data`` object includes the number of items available in |
| 446 ``@total_size``. A a ``collection`` list follows which contains the id | 446 ``@total_size``. A a ``collection`` list follows which contains the id |
| 447 and link to the respective item. For example a get on | 447 and link to the respective item. For example a get on |
| 472 a result all clients must be programmed to expect pagination | 472 a result all clients must be programmed to expect pagination |
| 473 decorations in the response. See the section on pagination below for | 473 decorations in the response. See the section on pagination below for |
| 474 details. | 474 details. |
| 475 | 475 |
| 476 Searching | 476 Searching |
| 477 ^^^^^^^^^ | 477 ~~~~~~~~~ |
| 478 | 478 |
| 479 Searching is done by adding roundup field names and values as query | 479 Searching is done by adding roundup field names and values as query |
| 480 parameters. Using: https://.../rest/data/issue you can search using: | 480 parameters. Using: https://.../rest/data/issue you can search using: |
| 481 | 481 |
| 482 .. list-table:: Query Parameters Examples | 482 .. list-table:: Query Parameters Examples |
| 547 body of a msg) is a work in progress. | 547 body of a msg) is a work in progress. |
| 548 | 548 |
| 549 .. _URL Encoding: https://en.wikipedia.org/wiki/Percent-encoding | 549 .. _URL Encoding: https://en.wikipedia.org/wiki/Percent-encoding |
| 550 | 550 |
| 551 Transitive Searching | 551 Transitive Searching |
| 552 ~~~~~~~~~~~~~~~~~~~~ | 552 ^^^^^^^^^^^^^^^^^^^^ |
| 553 | 553 |
| 554 In addition to searching an issue by its properties, you can search | 554 In addition to searching an issue by its properties, you can search |
| 555 for issues where linked items have a certain property. For example | 555 for issues where linked items have a certain property. For example |
| 556 using ``/issues?messages.author=1`` will find all issues that include | 556 using ``/issues?messages.author=1`` will find all issues that include |
| 557 (link to) a message created by the admin user. This can also be done | 557 (link to) a message created by the admin user. This can also be done |
| 570 user. Note that users can search a field even if they can't view | 570 user. Note that users can search a field even if they can't view |
| 571 it. However they may be able to use searches to discover the value of | 571 it. However they may be able to use searches to discover the value of |
| 572 the field even if they can't view it. | 572 the field even if they can't view it. |
| 573 | 573 |
| 574 Sorting | 574 Sorting |
| 575 ^^^^^^^ | 575 ~~~~~~~ |
| 576 | 576 |
| 577 Collection endpoints support sorting. This is controlled by specifying a | 577 Collection endpoints support sorting. This is controlled by specifying a |
| 578 ``@sort`` parameter with a list of properties of the searched class. | 578 ``@sort`` parameter with a list of properties of the searched class. |
| 579 Optionally properties can include a sign ('+' or '-') to specify | 579 Optionally properties can include a sign ('+' or '-') to specify |
| 580 ascending or descending sort, respectively. If no sign is given, | 580 ascending or descending sort, respectively. If no sign is given, |
| 584 | 584 |
| 585 @sort=status,-id | 585 @sort=status,-id |
| 586 | 586 |
| 587 | 587 |
| 588 Pagination | 588 Pagination |
| 589 ^^^^^^^^^^ | 589 ~~~~~~~~~~ |
| 590 | 590 |
| 591 Collection endpoints support pagination. This is controlled by query | 591 Collection endpoints support pagination. This is controlled by query |
| 592 parameters ``@page_size`` and ``@page_index`` (Note the use of the | 592 parameters ``@page_size`` and ``@page_index`` (Note the use of the |
| 593 leading `@` to make the parameters distinguishable from field names.) | 593 leading `@` to make the parameters distinguishable from field names.) |
| 594 | 594 |
| 643 entries in the collection as a DOS prevention measure. As a result | 643 entries in the collection as a DOS prevention measure. As a result |
| 644 clients must be prepared to handle the incomplete response and request | 644 clients must be prepared to handle the incomplete response and request |
| 645 the next URL to retrieve all of the entries. | 645 the next URL to retrieve all of the entries. |
| 646 | 646 |
| 647 Field embedding and verbose output | 647 Field embedding and verbose output |
| 648 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | 648 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 649 | 649 |
| 650 In collections, you can specify what fields should be embedded in the | 650 In collections, you can specify what fields should be embedded in the |
| 651 returned data. There are some shortcuts provided using the | 651 returned data. There are some shortcuts provided using the |
| 652 ``@verbose`` parameter. All the examples in this section are for a GET | 652 ``@verbose`` parameter. All the examples in this section are for a GET |
| 653 operation on ``https://.../rest/data/issue``. | 653 operation on ``https://.../rest/data/issue``. |
| 736 | 736 |
| 737 See the `Searches and selection`_ section for the use cases supported | 737 See the `Searches and selection`_ section for the use cases supported |
| 738 by these features. | 738 by these features. |
| 739 | 739 |
| 740 Getting Message and Files Content | 740 Getting Message and Files Content |
| 741 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | 741 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 742 | 742 |
| 743 You can retreive a message with a url like | 743 You can retreive a message with a url like |
| 744 ``https://.../demo/rest/data/msg/11``. This returns something like:: | 744 ``https://.../demo/rest/data/msg/11``. This returns something like:: |
| 745 | 745 |
| 746 { | 746 { |
| 848 | 848 |
| 849 You can use the `binary_content property`_ described below to | 849 You can use the `binary_content property`_ described below to |
| 850 retrieve an encoded copy of the data. | 850 retrieve an encoded copy of the data. |
| 851 | 851 |
| 852 Other query params | 852 Other query params |
| 853 ^^^^^^^^^^^^^^^^^^ | 853 ~~~~~~~~~~~~~~~~~~ |
| 854 | 854 |
| 855 This table lists other supported parameters: | 855 This table lists other supported parameters: |
| 856 | 856 |
| 857 .. list-table:: Query Parameters Examples | 857 .. list-table:: Query Parameters Examples |
| 858 :header-rows: 1 | 858 :header-rows: 1 |
| 867 You can disable pretty printing by using this query parameter. | 867 You can disable pretty printing by using this query parameter. |
| 868 Note the default is true, so @pretty=true is not supported at | 868 Note the default is true, so @pretty=true is not supported at |
| 869 this time. | 869 this time. |
| 870 | 870 |
| 871 Using the POST method | 871 Using the POST method |
| 872 ^^^^^^^^^^^^^^^^^^^^^ | 872 ~~~~~~~~~~~~~~~~~~~~~ |
| 873 | 873 |
| 874 Only class links support the ``POST`` method for creation of new items | 874 Only class links support the ``POST`` method for creation of new items |
| 875 of a class, e.g., a new issue via the ``/data/issue`` link. The post | 875 of a class, e.g., a new issue via the ``/data/issue`` link. The post |
| 876 gets a dictionary of keys/values for the new item. It returns the same | 876 gets a dictionary of keys/values for the new item. It returns the same |
| 877 parameters as the GET method after successful creation. | 877 parameters as the GET method after successful creation. |
| 990 return a 400 error. This is meant to allow the client (a time | 990 return a 400 error. This is meant to allow the client (a time |
| 991 limited way) to retrieve the created resource if the | 991 limited way) to retrieve the created resource if the |
| 992 response was lost. | 992 response was lost. |
| 993 | 993 |
| 994 Other Supported Methods for Collections | 994 Other Supported Methods for Collections |
| 995 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | 995 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 996 | 996 |
| 997 Supports the ``OPTIONS`` method for determining which methods are | 997 Supports the ``OPTIONS`` method for determining which methods are |
| 998 allowed on a given endpoint. | 998 allowed on a given endpoint. |
| 999 | 999 |
| 1000 Does not support PUT, DELETE or PATCH. | 1000 Does not support PUT, DELETE or PATCH. |
| 1001 | 1001 |
| 1002 /data/\ *class*/\ *id* item | 1002 /data/\ *class*/\ *id* item |
| 1003 =========================== | 1003 --------------------------- |
| 1004 | 1004 |
| 1005 When performing the ``GET`` method on an item | 1005 When performing the ``GET`` method on an item |
| 1006 (e.g. ``/data/issue/42``), a ``link`` attribute contains the link to | 1006 (e.g. ``/data/issue/42``), a ``link`` attribute contains the link to |
| 1007 the item, ``id`` contains the id, ``type`` contains the class name | 1007 the item, ``id`` contains the id, ``type`` contains the class name |
| 1008 (e.g. ``issue`` in the example) and an ``etag`` property can be used | 1008 (e.g. ``issue`` in the example) and an ``etag`` property can be used |
| 1081 "id": "23" | 1081 "id": "23" |
| 1082 } | 1082 } |
| 1083 } | 1083 } |
| 1084 | 1084 |
| 1085 Retrieve item using key value | 1085 Retrieve item using key value |
| 1086 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | 1086 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 1087 | 1087 |
| 1088 If the class has a key attribute, e.g. the 'status' class in the | 1088 If the class has a key attribute, e.g. the 'status' class in the |
| 1089 classic tracker, it can be used to retrieve the item. | 1089 classic tracker, it can be used to retrieve the item. |
| 1090 | 1090 |
| 1091 You can get an individual status by specifying the key-attribute value | 1091 You can get an individual status by specifying the key-attribute value |
| 1101 The long-form (with ``=``) is different from a query-parameter like | 1101 The long-form (with ``=``) is different from a query-parameter like |
| 1102 ``/data/status?name=closed`` which would find all stati (statuses) | 1102 ``/data/status?name=closed`` which would find all stati (statuses) |
| 1103 that have ``closed`` as a substring. | 1103 that have ``closed`` as a substring. |
| 1104 | 1104 |
| 1105 Dealing with Messages and Files | 1105 Dealing with Messages and Files |
| 1106 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | 1106 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 1107 | 1107 |
| 1108 Using the requests library you can upload a file using:: | 1108 Using the requests library you can upload a file using:: |
| 1109 | 1109 |
| 1110 d = dict (name = filename, content = content, type = content_type) | 1110 d = dict (name = filename, content = content, type = content_type) |
| 1111 j = self.post ('file', data = d) | 1111 j = self.post ('file', data = d) |
| 1145 } | 1145 } |
| 1146 } | 1146 } |
| 1147 | 1147 |
| 1148 | 1148 |
| 1149 Other Supported Methods for Items | 1149 Other Supported Methods for Items |
| 1150 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | 1150 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 1151 | 1151 |
| 1152 The method ``PUT`` is allowed on individual items, e.g. | 1152 The method ``PUT`` is allowed on individual items, e.g. |
| 1153 ``/data/issue/42`` On success it returns the same parameters as the | 1153 ``/data/issue/42`` On success it returns the same parameters as the |
| 1154 respective ``GET`` method. Note that for ``PUT`` an Etag has to be | 1154 respective ``GET`` method. Note that for ``PUT`` an Etag has to be |
| 1155 supplied, either in the request header or as an @etag parameter. An | 1155 supplied, either in the request header or as an @etag parameter. An |
| 1300 ``If-Match`` header. If you are using ``PUT`` or ``PATCH`` an | 1300 ``If-Match`` header. If you are using ``PUT`` or ``PATCH`` an |
| 1301 ``@etag`` value can be supplied in the payload in place of the | 1301 ``@etag`` value can be supplied in the payload in place of the |
| 1302 ``If-Match`` header. | 1302 ``If-Match`` header. |
| 1303 | 1303 |
| 1304 /data/\ *class*/\ *id*/\ *property* field | 1304 /data/\ *class*/\ *id*/\ *property* field |
| 1305 ========================================= | 1305 ----------------------------------------- |
| 1306 | 1306 |
| 1307 A ``GET`` method on a property (e.g. ``/data/issue/42/title``) returns the | 1307 A ``GET`` method on a property (e.g. ``/data/issue/42/title``) returns the |
| 1308 link, an ``@etag``, the type of the property (e.g. "<type str>") the id | 1308 link, an ``@etag``, the type of the property (e.g. "<type str>") the id |
| 1309 of the item and the content of the property in ``data``. | 1309 of the item and the content of the property in ``data``. |
| 1310 | 1310 |
| 1323 | 1323 |
| 1324 All endpoints support an ``OPTIONS`` method for determining which | 1324 All endpoints support an ``OPTIONS`` method for determining which |
| 1325 methods are allowed on a given endpoint. | 1325 methods are allowed on a given endpoint. |
| 1326 | 1326 |
| 1327 Message and File Content | 1327 Message and File Content |
| 1328 ^^^^^^^^^^^^^^^^^^^^^^^^ | 1328 ~~~~~~~~~~~~~~~~~~~~~~~~ |
| 1329 | 1329 |
| 1330 Messages and files have content properties. If the data is utf-8 | 1330 Messages and files have content properties. If the data is utf-8 |
| 1331 compatible (e.g. an email message) you can retrieve it with | 1331 compatible (e.g. an email message) you can retrieve it with |
| 1332 rest/data/msg/11/content to obtain:: | 1332 rest/data/msg/11/content to obtain:: |
| 1333 | 1333 |
| 1367 | 1367 |
| 1368 The data is a json encoded hexidecimal representation of the data. | 1368 The data is a json encoded hexidecimal representation of the data. |
| 1369 | 1369 |
| 1370 | 1370 |
| 1371 Other Supported Methods for fields | 1371 Other Supported Methods for fields |
| 1372 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | 1372 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 1373 | 1373 |
| 1374 The method ``PUT`` is allowed on a property e.g., | 1374 The method ``PUT`` is allowed on a property e.g., |
| 1375 ``/data/issue/42/title``. On success it returns the same parameters as | 1375 ``/data/issue/42/title``. On success it returns the same parameters as |
| 1376 the respective ``GET`` method. Note that for ``PUT`` an Etag has to be | 1376 the respective ``GET`` method. Note that for ``PUT`` an Etag has to be |
| 1377 supplied, either in the request header or as an @etag parameter. | 1377 supplied, either in the request header or as an @etag parameter. |
| 1419 ``If-Match`` header. If you are using ``PUT`` or ``PATCH`` an | 1419 ``If-Match`` header. If you are using ``PUT`` or ``PATCH`` an |
| 1420 ``@etag`` value can be supplied in the payload in place of the | 1420 ``@etag`` value can be supplied in the payload in place of the |
| 1421 ``If-Match`` header. | 1421 ``If-Match`` header. |
| 1422 | 1422 |
| 1423 Tunneling Methods via POST | 1423 Tunneling Methods via POST |
| 1424 ========================== | 1424 -------------------------- |
| 1425 | 1425 |
| 1426 If you are working through a proxy and unable to use http methods like | 1426 If you are working through a proxy and unable to use http methods like |
| 1427 PUT, PATCH, or DELETE, you can use POST to perform the action. To tunnel | 1427 PUT, PATCH, or DELETE, you can use POST to perform the action. To tunnel |
| 1428 an action through POST, send the ``X-HTTP-METHOD-OVERRIDE`` header | 1428 an action through POST, send the ``X-HTTP-METHOD-OVERRIDE`` header |
| 1429 with a value of DELETE or other capitalized HTTP verb. The body of the | 1429 with a value of DELETE or other capitalized HTTP verb. The body of the |
| 1430 POST should be what you would send if you were using the method | 1430 POST should be what you would send if you were using the method |
| 1431 without tunneling. | 1431 without tunneling. |
| 1432 | 1432 |
| 1433 Examples and Use Cases | 1433 Examples and Use Cases |
| 1434 ---------------------- | 1434 ====================== |
| 1435 | 1435 |
| 1436 sample python client | 1436 sample python client |
| 1437 ==================== | 1437 -------------------- |
| 1438 | 1438 |
| 1439 The client uses the python ``requests`` library for easier interaction | 1439 The client uses the python ``requests`` library for easier interaction |
| 1440 with a REST API supporting JSON encoding:: | 1440 with a REST API supporting JSON encoding:: |
| 1441 | 1441 |
| 1442 | 1442 |
| 1514 -X PATCH \ | 1514 -X PATCH \ |
| 1515 https://tracker.example.com/demo/rest/data/status/1 | 1515 https://tracker.example.com/demo/rest/data/status/1 |
| 1516 | 1516 |
| 1517 | 1517 |
| 1518 Searches and selection | 1518 Searches and selection |
| 1519 ====================== | 1519 ---------------------- |
| 1520 | 1520 |
| 1521 One difficult interface issue is selection of items from a long list. | 1521 One difficult interface issue is selection of items from a long list. |
| 1522 Using multi-item selects requires loading a lot of data (e.g. consider | 1522 Using multi-item selects requires loading a lot of data (e.g. consider |
| 1523 a selection tool to select one or more issues as in the classic | 1523 a selection tool to select one or more issues as in the classic |
| 1524 superseder field). | 1524 superseder field). |
| 1609 etc. can be generated. Also depending on the javascript library, other | 1609 etc. can be generated. Also depending on the javascript library, other |
| 1610 fields can be used for subsearch and sorting. | 1610 fields can be used for subsearch and sorting. |
| 1611 | 1611 |
| 1612 | 1612 |
| 1613 Programming the REST API | 1613 Programming the REST API |
| 1614 ------------------------ | 1614 ======================== |
| 1615 | 1615 |
| 1616 You can extend the rest api for a tracker. This describes how to add | 1616 You can extend the rest api for a tracker. This describes how to add |
| 1617 new rest end points. At some point it will also describe the rest.py | 1617 new rest end points. At some point it will also describe the rest.py |
| 1618 structure and implementation. | 1618 structure and implementation. |
| 1619 | 1619 |
| 1620 Adding new rest endpoints | 1620 Adding new rest endpoints |
| 1621 ========================= | 1621 ------------------------- |
| 1622 | 1622 |
| 1623 Add or edit the file `interfaces.py`_ at the root of the tracker | 1623 Add or edit the file `interfaces.py`_ at the root of the tracker |
| 1624 directory. | 1624 directory. |
| 1625 | 1625 |
| 1626 In that file add:: | 1626 In that file add:: |
| 1690 | 1690 |
| 1691 Adding other endpoints (e.g. to allow an OPTIONS query against | 1691 Adding other endpoints (e.g. to allow an OPTIONS query against |
| 1692 ``/data/issue/@schema``) is left as an exercise for the reader. | 1692 ``/data/issue/@schema``) is left as an exercise for the reader. |
| 1693 | 1693 |
| 1694 Redefine/move rest endpoints | 1694 Redefine/move rest endpoints |
| 1695 ============================ | 1695 ---------------------------- |
| 1696 | 1696 |
| 1697 In addition to adding new endpoints, you can redefine existing | 1697 In addition to adding new endpoints, you can redefine existing |
| 1698 endpoints. Adding this as described above:: | 1698 endpoints. Adding this as described above:: |
| 1699 | 1699 |
| 1700 @Routing.route("/summary") | 1700 @Routing.route("/summary") |
| 1732 will make the response at /rest/data2/<class> be the same as what is | 1732 will make the response at /rest/data2/<class> be the same as what is |
| 1733 normally at /rest/data/<class>. | 1733 normally at /rest/data/<class>. |
| 1734 | 1734 |
| 1735 | 1735 |
| 1736 Controlling Access to Backend Data | 1736 Controlling Access to Backend Data |
| 1737 ================================== | 1737 ---------------------------------- |
| 1738 | 1738 |
| 1739 Roundup's schema is the primary access control mechanism. Roles and | 1739 Roundup's schema is the primary access control mechanism. Roles and |
| 1740 Permissions provide the ability to carefully control what data can be | 1740 Permissions provide the ability to carefully control what data can be |
| 1741 seen. | 1741 seen. |
| 1742 | 1742 |
| 1844 assuming user 4 is the only user with the Developer role. Note that | 1844 assuming user 4 is the only user with the Developer role. Note that |
| 1845 the url passes the ``roles=User`` filter option which is silently | 1845 the url passes the ``roles=User`` filter option which is silently |
| 1846 ignored. | 1846 ignored. |
| 1847 | 1847 |
| 1848 Changing Access Roles with JSON Web Tokens | 1848 Changing Access Roles with JSON Web Tokens |
| 1849 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | 1849 ------------------------------------------ |
| 1850 | 1850 |
| 1851 As discussed above Roundup's schema is the access control mechanism. | 1851 As discussed above Roundup's schema is the access control mechanism. |
| 1852 However you may want to integrate a third party system with roundup. | 1852 However you may want to integrate a third party system with roundup. |
| 1853 E.G. suppose you use a time tracking service that takes an issue id | 1853 E.G. suppose you use a time tracking service that takes an issue id |
| 1854 and keeps a running count of how much time was spent on it. Then with | 1854 and keeps a running count of how much time was spent on it. Then with |
| 2108 for ideas or add your own. | 2108 for ideas or add your own. |
| 2109 | 2109 |
| 2110 .. _thoughts on JWT credentials: https://issues.roundup-tracker.org/issue2551064 | 2110 .. _thoughts on JWT credentials: https://issues.roundup-tracker.org/issue2551064 |
| 2111 | 2111 |
| 2112 Final steps | 2112 Final steps |
| 2113 ^^^^^^^^^^^ | 2113 ~~~~~~~~~~~ |
| 2114 | 2114 |
| 2115 See the `upgrading directions`_ on how to use the ``updateconfig`` | 2115 See the `upgrading directions`_ on how to use the ``updateconfig`` |
| 2116 command to generate an updated copy of config.ini using | 2116 command to generate an updated copy of config.ini using |
| 2117 roundup-admin. Then set the ``JWT_secret`` to at least 32 characters | 2117 roundup-admin. Then set the ``JWT_secret`` to at least 32 characters |
| 2118 (more is better up to 512 bits). | 2118 (more is better up to 512 bits). |
| 2131 https://sourceforge.net/p/roundup/mailman/ for directions on | 2131 https://sourceforge.net/p/roundup/mailman/ for directions on |
| 2132 subscribing and for archives of the lists. | 2132 subscribing and for archives of the lists. |
| 2133 | 2133 |
| 2134 | 2134 |
| 2135 Creating Custom Rate Limits | 2135 Creating Custom Rate Limits |
| 2136 =========================== | 2136 --------------------------- |
| 2137 | 2137 |
| 2138 You can replace the default rate limiter that is configured using | 2138 You can replace the default rate limiter that is configured using |
| 2139 the tracker's ``config.ini``. You can return different rate | 2139 the tracker's ``config.ini``. You can return different rate |
| 2140 limits based on the user, time of day, phase of moon, request | 2140 limits based on the user, time of day, phase of moon, request |
| 2141 method (via self.client.request.command) etc. | 2141 method (via self.client.request.command) etc. |
| 2175 function. This new function uses values for the number of calls | 2175 function. This new function uses values for the number of calls |
| 2176 and period that are specific to a user. If either is set to 0, | 2176 and period that are specific to a user. If either is set to 0, |
| 2177 the defaults from ``config.ini`` file are used. | 2177 the defaults from ``config.ini`` file are used. |
| 2178 | 2178 |
| 2179 Test Examples | 2179 Test Examples |
| 2180 ^^^^^^^^^^^^^ | 2180 ~~~~~~~~~~~~~ |
| 2181 | 2181 |
| 2182 Rate limit tests:: | 2182 Rate limit tests:: |
| 2183 | 2183 |
| 2184 seq 1 300 | xargs -P 20 -n 1 curl --head -u user:password -si \ | 2184 seq 1 300 | xargs -P 20 -n 1 curl --head -u user:password -si \ |
| 2185 https://.../rest/data/status/new | grep Remaining | 2185 https://.../rest/data/status/new | grep Remaining |
