Hooks
Hooks are scripts which are triggered by HTTP requests. When your hook is active, any HTTP request sent to the hook endpoint will trigger the execution of the script.
Request object
from abstra.hooks import get_request
body, query, headers = get_request()
Function definition
def get_request(local_file=None):
Parameters
Keyword Arguments | |
---|---|
local_file (string) | Fallback file location for testing locally |
Returns
Returns | |
---|---|
(parsed json or string) | Body parsed according to content-type header |
(dict) | Query parameters |
(dict) | Headers |
Response object
To send the response you have to use on of our builtin utils functions send_response
or send_json
:
from abstra.hooks import send_response, send_json
send_response(body="plain text body")
send_json(data={'ok': True}, status_code=200, headers={"ABSTRA": "CLOUD"})
send_response
def send_response(body=None, status_code=200, headers=None, local_file=None):
Keyword Arguments | Description |
---|---|
body (string) | Plain text response body |
status_code (number) | Http response status code |
headers (dict) | Headers to be sent back |
local_file (string) | Fallback file location for testing locally |
send_json
def send_json(data=None, status_code=200, headers=None, local_file=None):
Keyword Arguments | Description |
---|---|
data (any serializable value) | Data to be serialized and sent back |
status_code (number) | Http response status code |
headers (dict) | Headers to be sent back, in addition to content-type: application/json |
local_file (string) | Fallback file location for testing locally |