Skip to main content
Skip table of contents

Responses

Content Types

JSON

Data Lab Functions developers can set the return HTTP status code, a message, and any other data that is needed. Data Lab Functions responses performs json.dumps() on endpoint cell output.

If the endpoint cell output is type dict and contains data key then the Data Lab Functions response will extract its contents from the data key and send its value as the response.

If the endpoint cell output is type dict and contains status key then the Data Lab Functions response will set the status of the HTTP response to the value of the status key. Note that unless the endpoint cell output contains a data key, then the status key will appear in the Data Lab Functions response.

CODE
#GET /response/with/data
{'status': 402, 'data': {'num1': 10, 'bool1': True, 'str1': 'Some string'}}

The above Data Lab Functions response would be: {"num1": 10, "bool1": true, "str1": "Some string"} and the HTTP response status would be 402.

CODE
#GET /response/without/data
my_result = {'num1': 10, 'num2': 30, 'bool1': True, 'str1': 'Some string'}
response = {'status': 402, 'my_result': my_result}

The above Data Lab Functions response would be: {"status": 402, "my_result": {"num1": 10, "num2": 30, "bool1": true, "str1": "Some string"}} and the HTTP response status would be 402.

HTML

CODE
# GET /html
html = '<h1>Hello World</h1>'
{'headers': {'Content-Type': 'text/html'}, 'data': html}
JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.