brx-node SDK
Thebrx-node
package is the official Node.js SDK for interacting with the BRX platform. It provides a simple and intuitive interface for creating, managing, and executing BRKs.
Installation
Basic Usage
API Reference
BRX Class
TheBRX
class is the main entry point for interacting with the BRX platform.
Constructor
accessToken
(required): Your BRX API keyoptions
(optional): Configuration optionsuse_brx_key
(default:true
): Whether to use the BRX API key for authenticationverbose
(default:false
): Enable verbose loggingsend_local
(default:false
): Use local API endpoint (for development)force_client
(default:false
): Force client-side WebSocketsilent
(default:false
): Disable welcome message
Methods
get
brxID
(required): The ID of the BRK to fetch- Returns: A promise that resolves to the BRK schema
run
query
(required): The BRK to executecallback
(optional): A callback function that will be called for each result- Returns: A promise that resolves to an array of results
create
modifyRequest
(required): The BRK creation request- Returns: A promise that resolves to the creation result
update
modifyRequest
(required): The BRK update request- Returns: A promise that resolves to the update result
delete
modifyRequest
(required): The BRK deletion request- Returns: A promise that resolves to the deletion result
clone
modifyRequest
(required): The BRK clone request- Returns: A promise that resolves to the clone result
execute
run
instead.
query
(required): The BRK or query stream request to executecallback
(optional): A callback function that will be called for each result- Returns: A promise that resolves to an array of results
modify
create
, update
, delete
, or clone
instead.
modifyRequest
(required): The BRK modification request- Returns: A promise that resolves to the modification result
BRK Class
TheBRK
class represents a BRK (BRX Knowledge Representation) that can be executed.
Constructor
BRKSchema
(optional): The BRK schemaBRXClient
(optional): The BRX client to use for execution
Properties
input
brxQuery
inprogress
Methods
run
callback
(optional): A callback function that will be called for each result- Returns: A promise that resolves to an array of results
updateBRK
verbose
(optional): Enable verbose logging- Returns: A promise that resolves to an object containing the updated BRK query
Examples
Creating a BRK
Using a BRK with Dependencies
Error Handling
Advanced Usage
WebSocket Connections
The BRX client uses WebSockets for real-time communication with the BRX platform. You can customize the WebSocket behavior using the constructor options.Custom Processing
You can customize how BRKs are processed by setting theprocessType
property in the processParams
object.
Working with Maps
The BRX SDK uses JavaScriptMap
objects for certain properties. When serializing these objects to JSON, you need to use the mapReplacer
function.
Map
properties, you need to use the mapReviver
function.
Troubleshooting
Common Issues
- Authentication Errors: Make sure your API key is correct and has not expired.
- Network Errors: Check your internet connection and firewall settings.
- Rate Limiting: The BRX API has rate limits. If you’re making too many requests, you may be temporarily blocked.
- Invalid BRK IDs: Make sure the BRK IDs you’re using exist and are accessible to your account.
Debugging
You can enable verbose logging to help debug issues:Further Reading
- BRX API Reference
- [Core Concepts: BRK](/docs/Core Concepts/BRK)
- [Core Concepts: BRX Client](/docs/Core Concepts/BRXClient)
- [Core Concepts: Composability](/docs/Core Concepts/Composability)