blob: 0175a628acf52749144e0289fbe81a767f2ff647 [file] [log] [blame]
David Pursehouseed321322013-05-17 13:53:32 +01001Gerrit Code Review - REST API Developers' Notes
2===============================================
3
4This document is about developing the REST API. For details of the
5actual APIs available in Gerrit, please see the
6link:rest-api.html[REST API interface reference].
7
8
9Testing REST API Functionality
10------------------------------
11
12
13Basic Testing
14~~~~~~~~~~~~~
15
16Basic testing of REST API functionality can be done with `curl`:
17
18----
19 curl http://localhost:8080/path/to/api/
20----
21
22By default, `curl` sends `GET` requests. To test APIs with `PUT`, `POST`,
23or `DELETE`, an additional argument is required:
24
25----
26 curl -X PUT http://localhost:8080/path/to/api/
27 curl -X POST http://localhost:8080/path/to/api/
28 curl -X DELETE http://localhost:8080/path/to/api/
29----
30
31
32Sending Data in the Request
33~~~~~~~~~~~~~~~~~~~~~~~~~~~
34
35Some REST APIs accept data in the request body of `PUT` and `POST` requests.
36
37Test data can be included from a local file:
38
39----
40 curl -X PUT -d@testdata.txt --header "Content-Type: application/json" http://localhost:8080/path/to/api/
41----
42
Sasa Zivkov54493792013-05-29 16:43:35 +020043Note that the `-d` option will remove the newlines from the content of the
44local file. If the content should be sent as-is then use the `--data-binary`
45option instead:
46
47----
48 curl -X PUT --data-binary @testdata.txt --header "Content-Type: text/plain" http://localhost:8080/path/to/api/
49----
50
David Pursehouseed321322013-05-17 13:53:32 +010051
52Authentication
53~~~~~~~~~~~~~~
54
55To test APIs that require authentication, the username and password must be specified on
56the command line:
57
58----
59 curl --digest --user username:password http://localhost:8080/a/path/to/api/
60----
61
62This makes it easy to switch users for testing of permissions.
63
64It is also possible to test with a username and password from the `.netrc`
65file (on Windows, `_netrc`):
66
67----
68 curl --digest -n http://localhost:8080/a/path/to/api/
69----
70
71In both cases, the password should be the user's link:user-upload.html#http[HTTP password].
72
73
74Verifying Header Content
75~~~~~~~~~~~~~~~~~~~~~~~~
76
77To verify the headers returned from a REST API call, use `curl` in verbose mode:
78
79----
80 curl -v -n --digest -X DELETE http://localhost:8080/a/path/to/api/
81----
82
83The headers on both the request and the response will be printed.
84
85
86GERRIT
87------
88Part of link:index.html[Gerrit Code Review]
89