|
| 1 | +--- |
| 2 | +sidebarDepth: 3 |
| 3 | +--- |
| 4 | + |
1 | 5 | # HTTP API |
2 | 6 |
|
3 | | -xrDebug HTTP API standard defines a language-agnostic web service as variable introspection is generated on client-side. |
| 7 | +The HTTP API provides a RESTful interface to the server. See the [openapi.yml](https://raw.githubusercontent.com/xrdebug/xrdebug/refs/heads/3.0/api/openapi.yml) file for alternative API documentation. |
| 8 | + |
| 9 | +## Endpoints |
| 10 | + |
| 11 | +### GET / |
| 12 | + |
| 13 | +To access the web interface, open a web browser and navigate to the server's root URL. The server will serve the web interface. |
| 14 | + |
| 15 | +```sh |
| 16 | +open http://localhost:27420 |
| 17 | +``` |
| 18 | + |
| 19 | +### POST /messages |
| 20 | + |
| 21 | +Sends a message to the server. |
4 | 22 |
|
5 | | -Following examples use [curl](https://curl.se/) to issue HTTP requests to xrDebug API. |
| 23 | +**Parameters:** |
6 | 24 |
|
7 | | -## Create debug message |
| 25 | +All parameters are optional, but at least one is required. |
8 | 26 |
|
9 | | -`POST /messages` |
| 27 | +- `body`: The message body. |
| 28 | +- `emote`: The message type (default: `info`). |
| 29 | +- `file_line`: The line number. |
| 30 | +- `file_path`: The file path. |
| 31 | +- `id`: The message ID. |
| 32 | +- `topic`: The message topic. |
10 | 33 |
|
11 | | -When creating a debug message it will be streamed to xrDebug window. |
| 34 | +**Responses:** |
12 | 35 |
|
13 | | -All parameters are optional: `body`, `emote`, `file_line`, `file_path`, `id`, `topic` (but at least one is required). |
| 36 | +- `200 OK`: Message sent. |
| 37 | +- `400 Bad Request`: Invalid request. |
14 | 38 |
|
15 | 39 | ```sh |
16 | 40 | curl --fail -X POST \ |
17 | 41 | --data "body=My message" \ |
18 | 42 | --data "file_path=file" \ |
19 | 43 | --data "file_line=1" \ |
20 | | - http://127.0.0.1:27420/messages |
| 44 | + http://localhost:27420/messages |
21 | 45 | ``` |
22 | 46 |
|
23 | | -## Create pause |
| 47 | +### POST /pauses |
24 | 48 |
|
25 | | -`POST /pauses` |
| 49 | +Creates a pause lock. |
26 | 50 |
|
27 | | -When creating a pause, a lock for the given id will be created. When the helper sends `xri()->pause()` the debugger creates a lock with `{"stop":false}` contents. |
| 51 | +**Parameters:** |
28 | 52 |
|
29 | | -Requires `id`, supports optional body fields: `body`, `emote`, `file_line`, `file_path`, `topic`. |
| 53 | +- `id`: The ID of the pause lock. |
30 | 54 |
|
31 | | -```sh |
32 | | -curl --fail -X POST \ |
33 | | - --data "id=b1cabc9a-145f-11ee-be56-0242ac120002" \ |
34 | | - http://127.0.0.1:27420/pauses |
35 | | -``` |
| 55 | +The following parameters are optional: |
36 | 56 |
|
37 | | -## Get pause |
| 57 | +- `body`: The message body. |
| 58 | +- `emote`: The message type (default: `info`). |
| 59 | +- `file_line`: The line number. |
| 60 | +- `file_path`: The file path. |
| 61 | +- `topic`: The message topic |
38 | 62 |
|
39 | | -`GET /pauses/{id}` |
| 63 | +**Responses:** |
40 | 64 |
|
41 | | -If a pause exists it means that execution is paused for the given id. The helper which called `xri()->pause()` should sleep/wait while the pause exists. If pause contents are `{"stop":false}` the id is paused, if contents are `{"stop":true}` the id is stopped. |
| 65 | +- `201 Created`: Lock created `Location: /pauses/{id}`. |
| 66 | +- `409 Conflict`: Lock already exists. |
42 | 67 |
|
43 | 68 | ```sh |
44 | | -curl --fail -X GET \ |
45 | | - http://127.0.0.1:27420/pauses/b1cabc9a-145f-11ee-be56-0242ac120002 |
| 69 | +curl --fail -X POST --data "id=123" http://localhost:27420/pauses |
46 | 70 | ``` |
47 | 71 |
|
48 | | -## Delete pause |
| 72 | +### GET /pauses/{id} |
| 73 | + |
| 74 | +Retrieves the status of an existing pause lock. |
| 75 | + |
| 76 | +**Parameters:** |
49 | 77 |
|
50 | | -`DELETE /pauses/{id}` |
| 78 | +- `id` (path): The ID of the pause lock. |
51 | 79 |
|
52 | | -When deleting a pause the lock previously created will be removed, which will enable client library to continue code execution. |
| 80 | +**Responses:** |
| 81 | + |
| 82 | +- `200 OK`: Returns the pause lock (JSON). |
| 83 | +- `404 Not Found`: Lock not found. |
53 | 84 |
|
54 | 85 | ```sh |
55 | | -curl --fail -X DELETE \ |
56 | | - http://127.0.0.1:27420/pauses/b1cabc9a-145f-11ee-be56-0242ac120002 |
| 86 | +curl --fail -X GET http://localhost:27420/pauses/123 |
57 | 87 | ``` |
58 | 88 |
|
59 | | -## Update pause (stop execution) |
| 89 | +### DELETE /pauses/{id} |
| 90 | + |
| 91 | +Deletes a pause lock. |
| 92 | + |
| 93 | +**Parameters:** |
| 94 | + |
| 95 | +- `id` (path): The ID of the pause lock. |
60 | 96 |
|
61 | | -`PATCH /pauses/{id}` |
| 97 | +**Responses:** |
62 | 98 |
|
63 | | -When updating a pause it will update the pause to a full stop. GET requests will return `{"stop":true}`. The helper which called `xri()->pause()` should stop execution once the pause was updated to stop code execution. |
| 99 | +- `204 No Content`: Lock deleted. |
| 100 | +- `404 Not Found`: Lock not found. |
64 | 101 |
|
65 | 102 | ```sh |
66 | | -curl --fail -X PATCH \ |
67 | | - http://127.0.0.1:27420/pauses/b1cabc9a-145f-11ee-be56-0242ac120002 |
| 103 | +curl --fail -X DELETE http://localhost:27420/pauses/123 |
68 | 104 | ``` |
69 | 105 |
|
70 | | -## Request signing |
| 106 | +### PATCH /pauses/{id} |
| 107 | + |
| 108 | +Updates a pause lock status to `stop: true`. |
| 109 | + |
| 110 | +**Parameters:** |
| 111 | + |
| 112 | +- `id` (path): The ID of the pause lock. |
71 | 113 |
|
72 | | -When using sign verification (`-v` option) requests must add the `X-Signature` header. |
| 114 | +**Responses:** |
73 | 115 |
|
74 | | -First, sign the data fields: |
| 116 | +- `200 OK`: Lock updated, returns the pause lock (JSON). |
| 117 | +- `404 Not Found`: Lock not found. |
75 | 118 |
|
76 | | -```php |
77 | | -$serialize = serialize($data); |
78 | | -$sign = $privateKey->sign($serialize); |
79 | | -$signature = base64_encode($sign); |
| 119 | +```sh |
| 120 | +curl --fail -X PATCH http://localhost:27420/pauses/123 |
80 | 121 | ``` |
81 | 122 |
|
82 | | -Then pass the signature header: |
| 123 | +### GET /stream |
| 124 | + |
| 125 | +Establishes a Server-Sent Events (SSE) connection. |
| 126 | + |
| 127 | +**Responses:** |
| 128 | + |
| 129 | +- `200 OK`: Returns the SSE stream. |
83 | 130 |
|
84 | 131 | ```sh |
85 | | -curl --fail -X POST \ |
86 | | - --data "body=My signed message" \ |
87 | | - --data "file_path=file" \ |
88 | | - --data "file_line=1" \ |
89 | | - -H "X-Signature: <signature>" \ |
90 | | - http://127.0.0.1:27420/messages |
| 132 | +curl --fail -X GET http://localhost:27420/stream |
91 | 133 | ``` |
0 commit comments