Ben Rohlfs | da0a62b | 2021-04-26 17:02:19 +0200 | [diff] [blame] | 1 | = Gerrit Code Review - JavaScript Plugin Rest API |
Viktar Donich | bc8088e | 2018-04-23 15:29:57 -0700 | [diff] [blame] | 2 | |
| 3 | This API is provided by link:pg-plugin-dev.html#plugin-rest-api[plugin.restApi()] |
| 4 | and provides interface for Gerrit REST API. |
| 5 | |
| 6 | == getLoggedIn |
| 7 | `repoApi.getLoggedIn()` |
| 8 | |
| 9 | Get user logged in status. |
| 10 | |
| 11 | .Params |
| 12 | - None |
| 13 | |
| 14 | .Returns |
| 15 | - Promise<boolean> |
| 16 | |
| 17 | == getVersion |
| 18 | `repoApi.getVersion()` |
| 19 | |
| 20 | Get server version. |
| 21 | |
| 22 | .Params |
| 23 | - None |
| 24 | |
| 25 | .Returns |
| 26 | - Promise<string> |
| 27 | |
Thomas Draebing | 996639a | 2019-10-24 17:09:28 +0200 | [diff] [blame] | 28 | == getConfig |
| 29 | `repoApi.getConfig()` |
| 30 | |
Ben Rohlfs | da0a62b | 2021-04-26 17:02:19 +0200 | [diff] [blame] | 31 | Returns the host config as a link:rest-api-config.html#server-info[ServerInfo] |
| 32 | object. |
Thomas Draebing | 996639a | 2019-10-24 17:09:28 +0200 | [diff] [blame] | 33 | |
| 34 | .Params |
| 35 | - None |
| 36 | |
| 37 | .Returns |
Ben Rohlfs | da0a62b | 2021-04-26 17:02:19 +0200 | [diff] [blame] | 38 | - Promise<ServerInfo> |
Thomas Draebing | 996639a | 2019-10-24 17:09:28 +0200 | [diff] [blame] | 39 | |
Viktar Donich | bc8088e | 2018-04-23 15:29:57 -0700 | [diff] [blame] | 40 | == get |
| 41 | `repoApi.get(url)` |
| 42 | |
| 43 | Issues a GET REST API call to the URL, returns Promise that is resolved to |
| 44 | parsed response on success. Returned Promise is rejected on network error. |
| 45 | |
| 46 | .Params |
| 47 | - *url* String URL without base path or plugin prefix. |
| 48 | |
| 49 | .Returns |
| 50 | - Promise<Object> Parsed response. |
| 51 | |
| 52 | == post |
| 53 | `repoApi.post(url, opt_payload)` |
| 54 | |
| 55 | Issues a POST REST API call to the URL, returns Promise that is resolved to |
| 56 | parsed response on success. Returned Promise is rejected on network error. |
| 57 | |
| 58 | .Params |
| 59 | - *url* String URL without base path or plugin prefix. |
| 60 | - *opt_payload* (optional) Object Payload to be sent with the request. |
| 61 | |
| 62 | .Returns |
| 63 | - Promise<Object> Parsed response. |
| 64 | |
| 65 | == put |
| 66 | `repoApi.put(url, opt_payload)` |
| 67 | |
| 68 | Issues a PUT REST API call to the URL, returns Promise that is resolved to |
| 69 | parsed response on success. Returned Promise is rejected on network error. |
| 70 | |
| 71 | .Params |
| 72 | - *url* String URL without base path or plugin prefix. |
| 73 | - *opt_payload* (optional) Object Payload to be sent with the request. |
| 74 | |
| 75 | .Returns |
| 76 | - Promise<Object> Parsed response. |
| 77 | |
| 78 | == delete |
| 79 | `repoApi.delete(url)` |
| 80 | |
| 81 | Issues a DELETE REST API call to the URL, returns Promise that is resolved to |
| 82 | parsed response on HTTP 204, and rejected otherwise. |
| 83 | |
| 84 | .Params |
| 85 | - *url* String URL without base path or plugin prefix. |
| 86 | |
| 87 | .Returns |
| 88 | - Promise<Response> Fetch API's Response object. |
| 89 | |
| 90 | == send |
| 91 | `repoApi.send(method, url, opt_payload)` |
| 92 | |
| 93 | Send payload and parse the response, if request succeeds. Returned Promise is |
| 94 | rejected with detailed message or HTTP error code on network error. |
| 95 | |
| 96 | .Params |
| 97 | - *method* String HTTP method. |
| 98 | - *url* String URL without base path or plugin prefix. |
| 99 | - *opt_payload* (optional) Object Respected for POST and PUT only. |
| 100 | |
| 101 | .Returns |
| 102 | - Promise<Object> Parsed response. |
| 103 | |
| 104 | == fetch |
| 105 | `repoApi.fetch(method, url, opt_payload)` |
| 106 | |
| 107 | Send payload and return native Response. This method is for low-level access, to |
| 108 | implement custom error handling and parsing. |
| 109 | |
| 110 | .Params |
| 111 | - *method* String HTTP method. |
| 112 | - *url* String URL without base path or plugin prefix. |
| 113 | - *opt_payload* (optional) Object Respected for POST and PUT only. |
| 114 | |
| 115 | .Returns |
| 116 | - Promise<Response> Fetch API's Response object. |