Query API
Execute an ad-hoc query (complex)
Changed onThis API endpoint returns bindings for the variables in the query.
For simpler JSON queries, you may use GET /v1/query instead.
post/v1/query
Request
- The document declares no server URL.
- Authnone required
- TypeScriptA function with typed inputs. Its response is checked against the schema.
Query parameters
prettyboolean
If true, response will be in a human-readable format.
explainstring
If set to full, response will include query explanations in addition to the result.
metricsboolean
If true, compiler performance metrics will be returned in the response.
Request body application/yaml
QSchema required
Response
Success
Example response
{
"result": [
{
"id": "example2",
"raw": "package opa.examples\\n\\nimport data.servers\\n\\nviolations[server] {\\n\\tserver = servers[_]\\n\\tserver.protocols[_] = \\\"http\\\"\\n\\tpublic_servers[server]\\n}\\n",
"ast": {
"package": {
"path": [
{
"type": "import",
"value": "data.opa.example"
}
]
},
"rules": [
{
"head": {
"name": "violations",
"key": {
"type": "var",
"value": "$0"
}
},
"body": [
{
"index": 1,
"terms": [
{
"type": "var"
}
]
}
]
}
]
}
}
],
"metrics": {
"timer_rego_input_parse_ns": 69994,
"timer_rego_query_parse_ns": 4096,
"timer_rego_query_compile_ns": 4096,
"timer_rego_query_eval_ns": 69994,
"timer_rego_module_parse_ns": 12345,
"timer_rego_module_compile_ns": 69994,
"timer_server_handler_ns": 631000,
"timer_server_read_bytes_ns": 631000,
"timer_query_compile_stage_build_comprehension_index_ns": 43000,
"timer_query_compile_stage_check_safety_ns": 852000,
"timer_query_compile_stage_check_types_ns": 577000,
"timer_query_compile_stage_check_undefined_funcs_ns": 426000,
"timer_query_compile_stage_check_unsafe_builtins_ns": 14000,
"timer_query_compile_stage_resolve_refs_ns": 3000,
"timer_query_compile_stage_rewrite_comprehension_terms_ns": 329000,
"timer_query_compile_stage_rewrite_dynamic_terms_ns": 27000,
"timer_query_compile_stage_rewrite_expr_terms_ns": 40000,
"timer_query_compile_stage_rewrite_local_vars_ns": 187000,
"timer_query_compile_stage_rewrite_to_capture_value_ns": 1178000,
"timer_query_compile_stage_rewrite_with_values_ns": 23000
},
"explanation": [
{
"op": "enter",
"type": "expr",
"node": {
"terms": [
{
"type": "var",
"value": "$term1"
}
]
}
}
]
}Changes
- breaking
removed the media type
application/x-yamlfrom the request body - info
added the media type
application/yamlto the request body
- breaking
- breaking
removed the media type
application/yamlfrom the request body - info
added the media type
application/x-yamlto the request body
- breaking