Skip to content

Commit 58a3cc5

Browse files
committed
Improve batch/sequence docs
1 parent a705e66 commit 58a3cc5

File tree

1 file changed

+26
-10
lines changed

1 file changed

+26
-10
lines changed

sogs/routes/general.py

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,27 @@ def get_caps():
3737
return jsonify(res), res_code
3838

3939

40-
def parse_batch_request(req):
41-
"""
42-
Checks a batch request dict for the required fields:
40+
batch_args = """
41+
Each individual batch subrequest is a list of dicts containing keys:
4342
44-
- method is required and must be one of GET/DELETE/POST/PUT
45-
- path is required and must begin with a /
43+
- `method` is required and must be one of GET/DELETE/POST/PUT
44+
- `path` is required and must begin with a /
4645
- for POST/PUT requests there must be exactly one of:
47-
- a json value under the 'json' key
48-
- a base64-encoded body under the 'b64' key
49-
- a raw bytes value under the 'bytes' key (not recommended for json)
50-
- headers may be provided, and must be a dict of k/v string pairs if provided.
46+
- a json value under the `json` key
47+
- a base64-encoded body under the `b64` key
48+
- a raw bytes value under the `bytes` key (not recommended for json)
49+
- `headers` may be provided, and must be a dict of k/v string pairs if provided.
50+
51+
If non-conforming data is encountered then the request is terminated with a Bad Request error
52+
code.
53+
"""
54+
55+
56+
def parse_batch_request(req):
57+
f"""
58+
Checks a batch request dict for the required fields.
5159
52-
If non-conforming data is encountered then a BAD_REQUEST request abort is raised.
60+
{batch_args}
5361
5462
Returns (method, path, headers, json, body). `headers` will be a dict (empty if no headers were
5563
provided); `json`/`body` will be None for GET/DELETE requests; `json` will simply be the `json`
@@ -124,6 +132,12 @@ def batch(_sequential=False):
124132
be attempted. There is no guarantee on the order in which requests will be carried out. (For
125133
sequential, related requests invoke via /sequence instead).
126134
135+
# Body
136+
137+
{batch_args}
138+
139+
# Return value
140+
127141
Returns a list of responses in the same order as the provided requests; each response consists
128142
of a dict containing:
129143
- code -- the numeric http response code (e.g. 200 for success)
@@ -171,6 +185,8 @@ def sequence():
171185
Like batch, responses are returned in the same order as requests, but unlike batch there may be
172186
fewer elements in the response list (if requests were stopped because of a non-2xx response).
173187
In such a case, the final, non-2xx response is still included as the final response value.
188+
189+
See [`/batch`](#post-batch) for arguments and response.
174190
"""
175191

176192
return batch(_sequential=True)

0 commit comments

Comments
 (0)