61698b14e0
We previous use the section title style like: Section level 1 =============== Section level 2 --------------- Which have a problem in Asciidoctor that the number of "="s or "-"s must match the number of characters in the header exactly, as a result it's easy to make mistakes while changing the titles. Asciidoctor provides a better style like: = Section level 1 == Section level 2 So we switched to this style. Also fixed a bug in replace_macros.py, which will not cause any problem in the old style. Change-Id: I811dd7238735d98f662767c17086152cd69aea02
86 lines
2.1 KiB
Plaintext
86 lines
2.1 KiB
Plaintext
= Gerrit Code Review - REST API Developers' Notes
|
|
|
|
This document is about developing the REST API. For details of the
|
|
actual APIs available in Gerrit, please see the
|
|
link:rest-api.html[REST API interface reference].
|
|
|
|
|
|
== Testing REST API Functionality
|
|
|
|
|
|
=== Basic Testing
|
|
|
|
Basic testing of REST API functionality can be done with `curl`:
|
|
|
|
----
|
|
curl http://localhost:8080/path/to/api/
|
|
----
|
|
|
|
By default, `curl` sends `GET` requests. To test APIs with `PUT`, `POST`,
|
|
or `DELETE`, an additional argument is required:
|
|
|
|
----
|
|
curl -X PUT http://localhost:8080/path/to/api/
|
|
curl -X POST http://localhost:8080/path/to/api/
|
|
curl -X DELETE http://localhost:8080/path/to/api/
|
|
----
|
|
|
|
|
|
=== Sending Data in the Request
|
|
|
|
Some REST APIs accept data in the request body of `PUT` and `POST` requests.
|
|
|
|
Test data can be included from a local file:
|
|
|
|
----
|
|
curl -X PUT -d@testdata.txt --header "Content-Type: application/json" http://localhost:8080/path/to/api/
|
|
----
|
|
|
|
Note that the `-d` option will remove the newlines from the content of the
|
|
local file. If the content should be sent as-is then use the `--data-binary`
|
|
option instead:
|
|
|
|
----
|
|
curl -X PUT --data-binary @testdata.txt --header "Content-Type: text/plain" http://localhost:8080/path/to/api/
|
|
----
|
|
|
|
|
|
=== Authentication
|
|
|
|
To test APIs that require authentication, the username and password must be specified on
|
|
the command line:
|
|
|
|
----
|
|
curl --digest --user username:password http://localhost:8080/a/path/to/api/
|
|
----
|
|
|
|
This makes it easy to switch users for testing of permissions.
|
|
|
|
It is also possible to test with a username and password from the `.netrc`
|
|
file (on Windows, `_netrc`):
|
|
|
|
----
|
|
curl --digest -n http://localhost:8080/a/path/to/api/
|
|
----
|
|
|
|
In both cases, the password should be the user's link:user-upload.html#http[HTTP password].
|
|
|
|
|
|
=== Verifying Header Content
|
|
|
|
To verify the headers returned from a REST API call, use `curl` in verbose mode:
|
|
|
|
----
|
|
curl -v -n --digest -X DELETE http://localhost:8080/a/path/to/api/
|
|
----
|
|
|
|
The headers on both the request and the response will be printed.
|
|
|
|
|
|
GERRIT
|
|
------
|
|
Part of link:index.html[Gerrit Code Review]
|
|
|
|
SEARCHBOX
|
|
---------
|