Note: The SEDA network won't be able to access your proxy node unless you expose it on a public IP or domain.
Start by generating the config.json (mandatory) and data-proxy-private-key.json (optional). The private key will be used for for signing data, which is optional but recommended, and can also be passed in as the following environment variable: SEDA_DATA_PROXY_PRIVATE_KEY.
bunstartinit
{"routeGroup":"proxy",// Will host at myproxy.com/proxy"routes": [ {"path":"/*","upstreamUrl":"https://.myapi.com/endpoint/{*}",// {*} will be string replaced with user's api endpoint"headers": {"x--api-key":"MY-API-KEY","accept":"application/json" } } ]}
To start your proxy run the following command:
# Disables the proofing mechanism so it's easier to debug the proxybunstartrun--disable-proof# The console will output something similiar:2024-08-1913:21:46.624info:Proxyroutesisat<http://127.0.0.1:5384/proxy/>
Your proxy now running!
Additional configuration
Multiple routes:
{"routeGroup":"proxy","routes": [ {"path":"/eth-usd","upstreamUrl":"<https://myapi.com/eth-usd>",// Default is GET"headers": {"x-api-key":"some-api-key", }, }, {"path":"/btc-usd","upstreamUrl":"<https://myapi.com/btc-usd>",// Allows for multiple method setting"method": ["GET","HEAD"],"headers": {"x-api-key":"some-api-key", }, }, ],}
Variables
The config.json has support for using variable routes by using :varName:
{"routeGroup":"proxy","routes": [ {"path":"/:coinA/:coinB",// Use {} to inject route variables"upstreamUrl":"<https://myapi.com/{:coinA}-{:coinB}>","headers": {"x-api-key":"some-api-key",// Can also be injected in the header"x-custom":"{:coinA}", }, }, ],}
JSON path
If you don't want to expose all API info you can use jsonPath to reduce the response:
{"routeGroup":"proxy","routes": [ {"path":"/planets/:planet","upstreamUrl":"<https://swapi.dev/api/planets/{:planet}>",// Calling the API <http://localhost:5384/proxy/planets/1> will only return "Tatooine" and omit the rest"jsonPath":"$.name","headers": {"x-api-key":"some-api-key", }, }, ],}
Fowarding headers
By default the data proxy node will only forward the content-type as a response. This can be configured to include more headers if desired:
{"routeGroup":"proxy","routes": [ {"path":"/planets/:planet","upstreamUrl":"<https://swapi.dev/api/planets/{:planet}>",// Now the API will also return the server header from SWApi"forwardRepsonseHeaders": ["content-type","server"],"headers": {"x-api-key":"some-api-key", }, }, ],}
Environment variables injection
Sometimes you don't want to expose your API key in a config file, or you have multiple environments running. The Data Proxy node has support for injecting environment variables through {$MY_ENV_VARIABLE}:
{"routeGroup":"proxy","routes": [ {// Everything will be injected in the URL"path":"/*","upstreamUrl":"<https://swapi.dev/api/{*}>","headers": {"x-api-key":"{$SECRET_API_KEY}", }, }, ],}
Wildcard routes
The Data Proxy node has support for wildcard routes, which allows you to quickly expose all your APIs:
{"routeGroup":"proxy","routes": [ {// Everything will be injected in the URL"path":"/*","upstreamUrl":"https://swapi.dev/api/{*}","headers": {"x-api-key":"some-api-key", }, }, ],}