Script Development / Response Data DFF.RESP
You can directly return plain JSON or text responses. When you need to control the HTTP status code, headers, download file name, or content type, use DFF.RESP(...).
For disk files, use DFF.RESP_FILE(...); for MB-level data, use DFF.RESP_LARGE_DATA(...).
Parameters
| Parameter | Type | Required / Default | Description |
|---|---|---|---|
data |
Any JSON-serializable value | Required | Response body |
status_code |
int | 200 |
HTTP status code |
content_type |
str | None |
Response body type, e.g., json, text, html |
headers |
dict | None |
Additional response headers; no need to include Content-Type |
allow_304 |
bool | False |
Whether to allow the browser to use 304 caching |
download |
bool / str | False |
True generates a default file name; a string specifies the file name; once enabled, content_type no longer takes effect |
| Example | |
|---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | |
When constructing a response, whether data can be serialized is verified. If serialization fails, or if download is used together with data=None, the Func response will fail.
You must directly return the response object created by DFF.RESP(...); embedding it in other dictionaries or lists will not apply the status code, headers, or content type.
Warning
allow_304=True may let clients obtain cached content, so it should not be enabled when data changes frequently. Custom response headers must not contain secrets or other sensitive information.