3_example_requests
Env Setup
Make sure you install optional tools first:
make install_tools_optionalTest Relay with curl
curlAssuming you have an app staked for eth, you can query eth_blockNumber.
You can specify the service via the Target-Service-Id header:
curl http://localhost:3070/v1 \
-H "Target-Service-Id: eth" \
-H "Authorization: test_api_key" \
-d '{"jsonrpc": "2.0", "id": 1, "method": "eth_blockNumber" }'Or by using the eth subdomain:
curl http://eth.localhost:3070/v1 \
-H "Authorization: test_api_key" \
-d '{"jsonrpc": "2.0", "id": 1, "method": "eth_blockNumber" }'Expected response:
{ "id": 1, "jsonrpc": "2.0", "result": "0x2f01a" }Test WebSockets with wscat
wscatExpected terminal prompt:
And subscribe to events:
Which will start sending events like so:
This is a simple terminal-based Websocket example and does not contain reconnection logic.
Connections will drop on session rollover, which is expected behavior.
In production environments, you should implement reconnection logic and handle errors gracefully.
Load Testing Relays with relay-util
relay-utilYou can use this helper to send 100 requests with performance metrics:
Which runs the following command:
Load Testing WebSockets with websocket-load-test
websocket-load-testYou can use this helper to subscribe to events:
Subscribe to events:
Using Portal App ID instead of API Key
Portal App ID instead of API KeyFor the requests above, if your auth is configured to use Portal's authentication instead of API keys, you can send a request like so:
Or like so by sending the Portal-Application-ID header:
For WebSockets, the equivalent would be:
Or, by sending the Portal-Application-ID header:
Was this helpful?
