How FFI bindings work
The TLS Client is written in Go and compiled into a shared library that exposes C-compatible functions. These functions can be called from other languages using their respective FFI mechanisms:- Node.js: Uses
ffi-napito load and call shared library functions - Python: Uses
ctypesto interface with the shared library - C#: Uses
DllImportattributes for native interop
Available functions
The FFI interface exposes the following functions:request
Makes an HTTP request with custom TLS configuration. Parameters: JSON string containing request configuration Returns: JSON string with response datagetCookiesFromSession
Retrieves cookies from a specific session. Parameters: JSON string withsessionId and url
Returns: JSON string with cookies array
addCookiesToSession
Adds cookies to a session’s cookie jar. Parameters: JSON string withsessionId, url, and cookies array
Returns: JSON string with updated cookies
destroySession
Destroys a specific session and frees its resources. Parameters: JSON string withsessionId
Returns: JSON string with success status
destroyAll
Destroys all sessions and clears the session cache. Parameters: None Returns: JSON string with success statusfreeMemory
Frees memory allocated for a response. Parameters: Response ID string Returns: NoneRequest format
All requests are sent as JSON strings with the following structure:Response format
Responses are returned as JSON strings with the following structure:Error handling
When an error occurs, the response will have astatus of 0 and the error message will be in the body field:
Memory management
The FFI interface allocates memory for responses that must be freed to prevent memory leaks. Always callfreeMemory with the response ID after processing each response:
- Make a request and receive a response
- Parse the JSON response
- Extract the
idfield - Call
freeMemory(id)to free allocated memory
Sessions
Sessions allow you to maintain state across multiple requests, including:- Cookie jars for automatic cookie management
- Connection pooling for better performance
- TLS session resumption
- Include a
sessionIdin your request payload - Use the same
sessionIdfor subsequent requests - Call
destroySessionwhen done to free resources