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