Xray-docs-next/docs/en/config/api.md

105 lines
2.5 KiB
Markdown
Raw Normal View History

# API Interface
2021-05-26 11:05:53 +00:00
API interface configuration provides a set of APIs based on [gRPC](https://grpc.io/) for remote invocation.
2021-05-26 11:05:53 +00:00
The interface can be enabled through the api configuration module. When the api configuration is enabled, Xray will create an outbound proxy automatically. All incoming API connections need to be manually routed to this outbound proxy through [routing rule configuration](./routing.md).
2021-05-26 11:05:53 +00:00
Please refer to the [related configuration](#related-configuration) in this section.
2021-05-26 11:05:53 +00:00
::: warning
2023-03-12 02:00:26 +00:00
Most users do not need to use this API. Novices can ignore this item directly.
:::
2021-05-26 11:05:53 +00:00
## ApiObject
`ApiObject` corresponds to the `api` item in the configuration file.
2021-05-26 11:05:53 +00:00
```json
{
"api": {
"tag": "api",
"services": ["HandlerService", "LoggerService", "StatsService"]
}
}
```
> `tag`: string
Outbound proxy identifier.
2021-05-26 11:05:53 +00:00
> `services`: [string]
2021-05-26 11:05:53 +00:00
List of enabled APIs, optional values can be found in [Supported API List](#supported-api-list).
2021-05-26 11:05:53 +00:00
## Related Configuration
2021-05-26 11:05:53 +00:00
An api inbound can be added to the inbounds configuration.
2021-05-26 11:05:53 +00:00
```json
"inbounds": [
{
"listen": "127.0.0.1",
"port": 10085,
"protocol": "dokodemo-door",
"settings": {
"address": "127.0.0.1"
},
"tag": "api"
}
]
```
Add routing rules for the api inbound in the routing configuration.
2021-05-26 11:05:53 +00:00
```json
"routing": {
"rules": [
{
"inboundTag": [
"api"
],
"outboundTag": "api",
"type": "field"
}
]
2021-05-26 11:05:53 +00:00
}
```
## Supported API List
2021-05-26 11:05:53 +00:00
### HandlerService
APIs that modify the inbound and outbound proxies, with the following available functions:
2021-05-26 11:05:53 +00:00
- Add a new inbound proxy;
- Add a new outbound proxy;
- Delete an existing inbound proxy;
- Delete an existing outbound proxy;
- Add a user to an inbound proxy (VMess, VLESS, Trojan, and Shadowsocks(v1.3.0+) only);
- Delete a user from an inbound proxy (VMess, VLESS, Trojan, and Shadowsocks(v1.3.0+) only);
2021-05-26 11:05:53 +00:00
### LoggerService
Supports restarting the built-in logger, which can be used in conjunction with logrotate to perform operations on log files.
2021-05-26 11:05:53 +00:00
### StatsService
Built-in data statistics service, see [Statistics Information](./stats.md) for details.
2022-12-26 03:09:17 +00:00
### ReflectionService
Supports gRPC clients to obtain the list of APIs from the server.
```bash
$ grpcurl -plaintext localhost:10085 list
grpc.reflection.v1alpha.ServerReflection
v2ray.core.app.proxyman.command.HandlerService
v2ray.core.app.stats.command.StatsService
xray.app.proxyman.command.HandlerService
xray.app.stats.command.StatsService
```
## API Calling Example
2022-12-26 03:09:17 +00:00
[Xray-API-documents](https://github.com/XTLS/Xray-API-documents) @crossfw