# Custom headers
The Trusted Twin platform allows you to use optional custom HTTP headers in requests to the Trusted Twin API.
# X-TrustedTwin
The X-TrustedTwin
header enhances the rule functionality through using variables passed by the User in the request to the Trusted Twin API. These variables are accessed via the DICT
rule variable.
# About
The DICT
rule variable in the request header follows the standard object description structure. The DICT
variable must be encoded to be passed safely within the header.
# Encoding
If you are using the Trusted Twin official Python library, you only need to provide the tt_dict
as a dictionary:
tt_dict = {"serial" : "123"}
TT_SERVICE = TTRESTService(tt_auth=$USER_SECRET, tt_dict=tt_dict)
In case you need to generate the value, you can use the Python function below:
from base64 import b64encode
from json import dumps
from typing import Dict, Any
def http_header_encode(dictionary: Dict[str, Any]) -> str:
return b64encode(dumps(dictionary).encode('utf-8')).decode('utf-8')
tt_dict = {"serial" : "123"}
encoded_dict = http_header_encode(tt_dict)
print(encoded_dict)
For other programming languages, use the same technique consisting of the following steps:
- convert
DICT
into its JSON representation encoded in UTF-8, - encode the string using base64 standard encoding.
# Example
Let's assume you want to pass the following dictionary in the header:
{"serial": "b0f531c3-914b-4408-9895-b61f59c06b66"}
After encoding, the header will look as follows:
'X-TrustedTwin: eyJzZXJpYWwiOiAiYjBmNTMxYzMtOTE0Yi00NDA4LTk4OTUtYjYxZjU5YzA2YjY2In0='
# Example usage scenario
To explore example scenario of X-TrustedTwin
header usage, please go to Custom headers guide.
Was this article helpful?