Using the API server#
clp-json includes an API server that provides a RESTful interface for interacting with CLP.
Note
Currently, the API server only supports clp-json. Support for clp-text will be
added in a future release.
Starting the API server#
CLP starts the API server based on the api_server section in etc/clp-config.yaml, which includes
a default configuration. You can uncomment and modify this section to override the defaults.
API reference#
All available API endpoints are defined in the OpenAPI Specification. You can explore the API using Swagger UI.
Example: Submitting search queries and receiving results#
The API server exposes endpoints to submit search queries, and returns search results as a continuous stream using Server-sent Events.
Assuming the server is running on the default host and port (localhost:3001), you can use the
following commands to submit a query to clp-json and stream the results.
Submit a search query:
curl -X POST http://localhost:3001/query \ -H "Content-Type: application/json" \ -d '{ "query_string": "*log*", "dataset": "default", "ignore_case": false, "max_num_results": 100, "write_to_file": false }'
On success, the server responds with:
{ "query_results_uri": "/query_results/100" }
Retrieve search results: Use the returned
query_results_urito receive search results as an SSE stream:curl -N http://localhost:3001/query_results/100
Example streamed output:
data: {"timestamp": 1633036800, "message": "Example log message"} data: {"timestamp": 1633036810, "message": "Another matched log line"} data: {"timestamp": 1633036820, "message": "No logs found" }