2.7 KiB
2.7 KiB
HTTP API Reference
Base: HTTP over a unix-domain socket. Example using curl: curl --unix-socket /path/to/socket -X POST http://localhost/<path>
-
GET /status
- Response: 200 OK
- Body: JSON
{ "ok": true }
-
POST /validate
- Request JSON:
{ "config_name": "example", "timestamp": 1234567890 }-
Behavior: validates the fragment file named by
config_nameandtimestampunder the agent's internal subdirectory inside the configured nginx config directory. Delegates toValidateCommand::validate. -
Success: 200 OK, body is
[rc, output]tuple serialized as JSON (actual shape is(i32, String)returned from the command; examine responses for exact formatting). -
Error cases:
- 400 Bad Request: invalid or malformed JSON
- 500 Internal Server Error: validation error or missing fragment file
-
Request JSON:
{ "config_name": "example", "timestamp": 1234567890 }- Behavior: validates the fragment file named by
config_nameandtimestampunder the agent's internal subdirectory inside the configured nginx config directory. Delegates toValidateCommand::validate. - Success: 200 OK, body is a JSON array
[rc, output]wherercis the integer return code andoutputis the combined stdout/stderr string from the validation command (the command returns an(i32, String)tuple). - Error cases:
- 400 Bad Request: invalid or malformed JSON
- 500 Internal Server Error: validation error or missing fragment file
-
POST /validate_and_reload
- Request JSON same as
/validate. - Behavior: runs validation and, on success, attempts to reload nginx. Returns an object with
rcandro(return code and combined stdout/stderr output). - Success: 200 OK with body:
{ "rc": <int>, "ro": "<output>" } - Errors: 400 for malformed JSON, 500 if the validate-and-reload command fails (body presents error text).
- Request JSON same as
-
POST /write_config
- Request JSON:
{ "config_name": "example", "timestamp": 1234567890, "content": "server { ... }" }- Behavior: writes the provided
contentinto an agent-managed fragment file named fromconfig_nameandtimestampin the internal subdirectory undernginx_config_dir. - Success: 200 OK with empty body
- Error: 400 for malformed JSON, 500 if writing the file fails
Notes
- The agent expects callers to choose a
config_nameandtimestampthat together form a unique filename. The concrete filename encoding is performed bycommands::run::to_file_namein source. - On validation failures the returned output often contains the full
nginx -toutput; inspectroor the returned JSON error messages.