blob: 869ac2b830f53db4e313b19e92c882548f5b47ec [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
43
44Authentication
45~~~~~~~~~~~~~~
46
47To test APIs that require authentication, the username and password must be specified on
48the command line:
49
50----
51 curl --digest --user username:password http://localhost:8080/a/path/to/api/
52----
53
54This makes it easy to switch users for testing of permissions.
55
56It is also possible to test with a username and password from the `.netrc`
57file (on Windows, `_netrc`):
58
59----
60 curl --digest -n http://localhost:8080/a/path/to/api/
61----
62
63In both cases, the password should be the user's link:user-upload.html#http[HTTP password].
64
65
66Verifying Header Content
67~~~~~~~~~~~~~~~~~~~~~~~~
68
69To verify the headers returned from a REST API call, use `curl` in verbose mode:
70
71----
72 curl -v -n --digest -X DELETE http://localhost:8080/a/path/to/api/
73----
74
75The headers on both the request and the response will be printed.
76
77
78GERRIT
79------
80Part of link:index.html[Gerrit Code Review]
81