Skip to content

Commit 828b8cb

Browse files
authored
docs: improve request headers documentation in REST APIs (#7524)
Signed-off-by: ali-jalaal <[email protected]>
1 parent 31c7d8b commit 828b8cb

File tree

1 file changed

+50
-16
lines changed

1 file changed

+50
-16
lines changed

docs/content/rest-api.md

+50-16
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,25 @@ OPA integration using one of the [language SDKs](/ecosystem/#languages) than wor
3636
with the REST API directly.
3737
{{< /info >}}
3838

39+
## Common Request Headers
40+
41+
The following request headers are commonly used in some API endpoints:
42+
43+
#### Content-Type
44+
45+
It indicates the request body format. These are some values used in some APIs:
46+
- `application/json` for JSON encoded content, e.g. a JSON document
47+
- `application/yaml` for YAML encoded content, e.g. a YAML document
48+
- `text/plain` for plain text content, e.g. a policy
49+
50+
#### Accept-Encoding
51+
52+
It could have `gzip` value which indicates the server should respond with a gzip encoded body. The server will send the compressed response only if its length is above `server.encoding.gzip.min_length` value. See the [configuration section](../configuration/#server).
53+
54+
#### Content-Encoding
55+
56+
It could have `gzip` value which indicates the request body is a gzip encoded object.
57+
3958
## Policy API
4059

4160
The Policy API exposes CRUD endpoints for managing policy modules. Policy modules can be added, removed, and modified at any time.
@@ -649,6 +668,10 @@ Create or update a policy module.
649668

650669
If the policy module does not exist, it is created. If the policy module already exists, it is replaced.
651670

671+
#### Request Headers
672+
673+
- **[Content-Type](#content-type)**: `text/plain`
674+
652675
#### Query Parameters
653676

654677
- **pretty** - If parameter is `true`, response will be formatted for humans.
@@ -751,6 +774,10 @@ Get a document.
751774

752775
The path separator is used to access values inside object and array documents. The server attempts to convert path segments to integers. If a path element cannot be converted to an integer, the server will use its string representation.
753776

777+
#### Request Headers
778+
779+
- **[Accept-Encoding](#accept-encoding)**: `gzip`
780+
754781
#### Query Parameters
755782

756783
- **input** - Provide an input document. Format is a JSON value that will be used as the value for the input document.
@@ -761,10 +788,6 @@ The path separator is used to access values inside object and array documents. T
761788
- **instrument** - Instrument query evaluation and return a superset of performance metrics in addition to result. See [Performance Metrics](#performance-metrics) for more detail.
762789
- **strict-builtin-errors** - Treat built-in function call errors as fatal and return an error immediately.
763790

764-
#### Request Headers
765-
766-
- **Accept-Encoding: gzip**: Indicates the server should respond with a gzip encoded body. The server will send the compressed response only if its length is above `server.encoding.gzip.min_length` value. See the configuration section
767-
768791
#### Status Codes
769792

770793
- **200** - no error
@@ -852,9 +875,9 @@ The request body contains an object that specifies a value for [The input Docume
852875

853876
#### Request Headers
854877

855-
- **Content-Type: application/yaml**: Indicates the request body is a YAML encoded object.
856-
- **Content-Encoding: gzip**: Indicates the request body is a gzip encoded object.
857-
- **Accept-Encoding: gzip**: Indicates the server should respond with a gzip encoded body. The server will send the compressed response only if its length is above `server.encoding.gzip.min_length` value. See the configuration section
878+
- **[Content-Type](#content-type)**: `application/json` or `application/yaml`
879+
- **[Content-Encoding](#content-encoding)**: `gzip`
880+
- **[Accept-Encoding](#accept-encoding)**: `gzip`
858881

859882
#### Query Parameters
860883

@@ -973,9 +996,9 @@ array documents.
973996

974997
#### Request Headers
975998

976-
- **Content-Type: application/yaml**: Indicates the request body is a YAML encoded object.
977-
- **Content-Encoding: gzip**: Indicates the request body is a gzip encoded object.
978-
- **Accept-Encoding: gzip**: Indicates the server should respond with a gzip encoded body. The server will send the compressed response only if its length is above `server.encoding.gzip.min_length` value. See the configuration section
999+
- **[Content-Type](#content-type)**: `application/json` or `application/yaml`
1000+
- **[Content-Encoding](#content-encoding)**: `gzip`
1001+
- **[Accept-Encoding](#accept-encoding)**: `gzip`
9791002

9801003
#### Query Parameters
9811004

@@ -1037,7 +1060,10 @@ Create or overwrite a document.
10371060

10381061
If the path does not refer to an existing document, the server will attempt to create all the necessary containing documents. This behavior is similar in principle to the Unix command `mkdir -p`.
10391062

1040-
The server will respect the `If-None-Match` header if it is set to `*`. In this case, the server will not overwrite an existing document located at the path.
1063+
#### Request Headers
1064+
1065+
- **[Content-Type](#content-type)**: `application/json`
1066+
- **If-None-Match**: `*` - the server will not overwrite an existing document located at the path.
10411067

10421068
#### Query Parameters
10431069

@@ -1090,6 +1116,11 @@ The server accepts updates encoded as JSON Patch operations. The message body of
10901116

10911117
The effective path of the JSON Patch operation is obtained by joining the path portion of the URL with the path value from the operation(s) contained in the message body. In all cases, the parent of the effective path MUST refer to an existing document, otherwise the server returns 404. In the case of **remove** and **replace** operations, the effective path MUST refer to an existing document, otherwise the server returns 404.
10921118

1119+
#### Request Headers
1120+
1121+
- **[Content-Type](#content-type)**: `application/json-patch+json`
1122+
1123+
10931124
#### Status Codes
10941125

10951126
- **204** - no content (success)
@@ -1175,7 +1206,7 @@ for more information.
11751206

11761207
#### Request Headers
11771208

1178-
- **Content-Type: application/yaml**: Indicates the request body is a YAML encoded object.
1209+
- **[Content-Type](#content-type)**: `application/json` or `application/yaml`
11791210

11801211
#### Query Parameters
11811212

@@ -1256,7 +1287,9 @@ GET /v1/query
12561287
- **500** - server error
12571288
- **501** - streaming not implemented
12581289

1259-
For queries that have large JSON values it is recommended to use the `POST` method with the query included as the `POST` body:
1290+
For queries that have large JSON values it is recommended to use the `POST` method with:
1291+
- the query included as the request body
1292+
- [Content-Type](#content-type): `application/json` request header
12601293

12611294
```
12621295
POST /v1/query HTTP/1.1
@@ -1336,10 +1369,11 @@ Compile API requests contain the following fields:
13361369
| `options` | `object[string, any]` | No | Additional options to use during partial evaluation: `disableInlining` (default: undefined) and `nondeterminsticBuiltins` (default: false). |
13371370
| `unknowns` | `array[string]` | No | The terms to treat as unknown during partial evaluation (default: `["input"]`]). |
13381371

1339-
### Request Headers
1372+
#### Request Headers
13401373

1341-
- **Content-Encoding: gzip**: Indicates the request body is a gzip encoded object.
1342-
- **Accept-Encoding: gzip**: Indicates the server should respond with a gzip encoded body. The server will send the compressed response only if its length is above `server.encoding.gzip.min_length` value
1374+
- **[Content-Type](#content-type)**: `application/json`
1375+
- **[Content-Encoding](#content-encoding)**: `gzip`
1376+
- **[Accept-Encoding](#accept-encoding)**: `gzip`
13431377

13441378
#### Query Parameters
13451379

0 commit comments

Comments
 (0)