Shawn O. Pearce | ec9efd7 | 2012-04-04 20:44:39 -0700 | [diff] [blame] | 1 | Gerrit Code Review - REST API |
| 2 | ============================= |
| 3 | |
| 4 | Gerrit Code Review comes with a REST like API available over HTTP. |
| 5 | The API is suitable for automated tools to build upon, as well as |
| 6 | supporting some ad-hoc scripting use cases. |
| 7 | |
| 8 | Protocol Details |
| 9 | ---------------- |
| 10 | |
Edwin Kempin | d089fc4 | 2012-07-18 14:58:40 +0200 | [diff] [blame] | 11 | [[authentication]] |
Shawn O. Pearce | ec9efd7 | 2012-04-04 20:44:39 -0700 | [diff] [blame] | 12 | Authentication |
| 13 | ~~~~~~~~~~~~~~ |
| 14 | By default all REST endpoints assume anonymous access and filter |
| 15 | results to correspond to what anonymous users can read (which may |
| 16 | be nothing at all). |
| 17 | |
| 18 | Users (and programs) may authenticate using HTTP authentication by |
| 19 | supplying the HTTP password from the user's account settings page. |
| 20 | Gerrit by default uses HTTP digest authentication. To authenticate, |
| 21 | prefix the endpoint URL with `/a/`. For example to authenticate to |
| 22 | `/projects/` request URL `/a/projects/`. |
| 23 | |
Shawn Pearce | a90a43a | 2013-01-26 12:50:56 -0800 | [diff] [blame^] | 24 | [[preconditions]] |
| 25 | Preconditions |
| 26 | ~~~~~~~~~~~~~ |
| 27 | Clients can request PUT to create a new resource and not overwrite |
| 28 | an existing one by adding `If-None-Match: *` to the request HTTP |
| 29 | headers. If the named resource already exists the server will respond |
| 30 | with HTTP 412 Precondition Failed. |
| 31 | |
Edwin Kempin | d089fc4 | 2012-07-18 14:58:40 +0200 | [diff] [blame] | 32 | [[output]] |
Shawn O. Pearce | ec9efd7 | 2012-04-04 20:44:39 -0700 | [diff] [blame] | 33 | Output Format |
| 34 | ~~~~~~~~~~~~~ |
Shawn O. Pearce | ea6d0b5 | 2012-11-16 10:57:31 -0800 | [diff] [blame] | 35 | Most APIs return pretty printed JSON by default. Compact JSON can be |
| 36 | requested by setting the `Accept` HTTP request header to include |
Shawn O. Pearce | ec9efd7 | 2012-04-04 20:44:39 -0700 | [diff] [blame] | 37 | `application/json`, for example: |
| 38 | |
| 39 | ---- |
| 40 | GET /projects/ HTTP/1.0 |
| 41 | Accept: application/json |
| 42 | ---- |
| 43 | |
| 44 | JSON responses are encoded using UTF-8 and use content type |
David Pursehouse | 221d4f6 | 2012-06-08 17:38:08 +0900 | [diff] [blame] | 45 | `application/json`. The JSON response body starts with a magic prefix |
Shawn O. Pearce | ec9efd7 | 2012-04-04 20:44:39 -0700 | [diff] [blame] | 46 | line that must be stripped before feeding the rest of the response |
| 47 | body to a JSON parser: |
| 48 | |
| 49 | ---- |
| 50 | )]}' |
| 51 | [ ... valid JSON ... ] |
| 52 | ---- |
| 53 | |
Shawn O. Pearce | ea6d0b5 | 2012-11-16 10:57:31 -0800 | [diff] [blame] | 54 | The default JSON format is pretty, which uses extra whitespace to make |
| 55 | the output more readable for a human. Producing (and parsing) the |
| 56 | non-pretty compact format is more efficient so tools should request it |
| 57 | by using the `Accept: application/json` header or `pp=0` query |
| 58 | parameter whenever possible. |
Shawn O. Pearce | ec9efd7 | 2012-04-04 20:44:39 -0700 | [diff] [blame] | 59 | |
| 60 | Responses will be gzip compressed by the server if the HTTP |
| 61 | `Accept-Encoding` request header is set to `gzip`. This may |
| 62 | save on network transfer time for larger responses. |
| 63 | |
| 64 | Endpoints |
| 65 | --------- |
Edwin Kempin | d0a6392 | 2013-01-23 16:32:59 +0100 | [diff] [blame] | 66 | link:rest-api-accounts.html[/accounts/]:: |
| 67 | Account related REST endpoints |
| 68 | link:rest-api-changes.html[/changes/]:: |
| 69 | Change related REST endpoints |
| 70 | link:rest-api-groups.html[/groups/]:: |
| 71 | Group related REST endpoints |
| 72 | link:rest-api-projects.html[/projects/]:: |
| 73 | Project related REST endpoints |
Shawn O. Pearce | ec9efd7 | 2012-04-04 20:44:39 -0700 | [diff] [blame] | 74 | |
| 75 | GERRIT |
| 76 | ------ |
| 77 | Part of link:index.html[Gerrit Code Review] |