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