RelayApp Frontend Integration

After completing Self Service node deployment, integrate it with the RelayApp frontend to achieve complete decentralized service call chains.

Get Service Key

Obtain a unique service-key, which is the identity credential for frontend communication with Self Service nodes:

Get service key (curl)
curl http://127.0.0.1:4567/getServiceKey

Successful response example:

{
    "code": 200,
    "data": "eyJhdXRoc2lnbiI6Ik1FVUNJUURhOFl..."
}

Integration Steps

1

Register Self Service in RelayApp

Use the obtained service-key to call RelayApp's registerService method:

// Example code (adjust according to actual RelayApp SDK)
let data = {
  serviceKey: "eyJhdXRoc2lnbiI6..." // Complete service-key from previous step
};

let signInfo = {
  content: "xxxxxxxx",
  signature: "xxxxxxx"
}; 

// Register Self Service
let result = await relay.registerService(data, signInfo);
2

Configure API Calls

Configure API calls to Self Service in the RelayApp frontend. All requests will be routed to your application service through the P2P network:

// Example: Call Self Service API
let data = {
    type: "HTTP",
    content: {
      method: "POST",
      url: "/add",
      headers: {
        "Content-Type": "application/json"
      },
      data: {
        id: "1",
        name: "Alice"
      }
    }
};

let signInfo = {
  content: "xxxxxxxx",
  signature: "xxxxxxx"
};

let result = await relay.sendServiceMessage(data, signInfo);
3

Handle Responses

Self Service responses will return to the RelayApp frontend through the P2P network, handled the same way as traditional HTTP APIs:

if (response.code === 200) {
    console.log("Request successful:", response.data);
} else {
    console.error("Request failed:", response.message);
}

Integration Verification

Verify the configuration is correct using the following methods:

  • Check Service Registration Status: View Self Service registration status in RelayApp

  • Initiate Test Requests: Call a simple API interface to verify requests can be routed correctly

  • View Logs: Check Self Service node logs to confirm requests have been processed correctly

chevron-rightView Self Service node logshashtag

Signs of Successful Integration

  • Service registration successful with no error logs

  • API calls can return responses normally

  • Self Service node logs show request processing records

  • Application service receives HTTP requests from Self Service nodes

Through the above configuration and integration steps, your application can securely access decentralized backend services through the RelayApp frontend, enjoying the privacy protection, censorship resistance, and cost advantages brought by the P2P network.