Make REST API calls

REL-ID Tunneling Overview

🔒 What is REL-ID Tunneling?

REL-ID Tunneling allows mobile apps to securely access backend APIs over a secure, MiTM-proof channel, eliminating the need for those APIs to be hosted in the public internet (DMZ). This helps:

  • Move API servers to a secure internal zone
  • Avoid public exposure
  • Route encrypted and authenticated traffic via REL-ID Gateway

🔁 Tunneling Methods

MethodPlatforms SupportedDescription
OpenHttpConnection APIiOS, Android, Cordova, React NativeSDK method to tunnel HTTPS requests through REL-ID Gateway
Proxy InterfaceAndroid (Native & React Native)HTTP Proxy setup at OS level to redirect all HTTP/HTTPS requests locally

Note: Proxy interface is not supported on iOS due to OS-level restrictions.


⚙️ Platform-wise Integration

✅ Native iOS (Objective-C)

📄OpenHttpConnection API for iOS (Objective-C)

Overview

The openHttpConnection API enables secure REST HTTP/HTTPS calls (GET, POST, HEAD, PUT, DELETE) through the REL-ID Gateway.

Prerequisites

  • Implement RDNAHTTPCallbacaks protocol.
  • Handle the onHttpResponse: method.

Example: Implementing RDNAHTTPCallbacks

-(int)onHttpResponse:(RDNAHTTPStatus *)status {
    if (status.errorCode == 0 && status.response.statusCode == 200) {
        NSError *jsonError;
        NSDictionary *json = [NSJSONSerialization JSONObjectWithData:status.response.body
                                                             options:NSJSONReadingMutableContainers
                                                               error:&jsonError];
        return 0;
    }
    return -1;
}

Example: Invoking openHttpConnection (POST request)

-(RDNAError *)openHttpConnection:(NSString*)url
                       andParams:(NSDictionary*)params
                     andCallback:(id<RDNAHTTPCallbacks>)callback {

    RDNAError *error;
    if (rdnaObject != nil) {
        RDNAHTTPRequest *request = [[RDNAHTTPRequest alloc] init];

        if (params) {
            NSError *err;
            NSData *data = [NSJSONSerialization dataWithJSONObject:params
                                                           options:NSJSONWritingPrettyPrinted
                                                             error:&err];
            id json = [NSJSONSerialization JSONObjectWithData:data options:0 error:&err];
            if (!err) {
                request.headers = json;
            }
        }

        request.method = RDNA_HTTP_POST;
        request.url = url;

        int requestID;
        error = [rdnaObject openHttpConnection:request
                                      Callbacks:(id)[RDNAClientCallBacks SharedInstance]
                                 httpRequestID:&requestID];

        if (error.longErrorCode > 0) {
            dispatch_async(dispatch_get_main_queue(), ^{
                // Store request ID and wait for response
            });
        }
    }

    return error;
}


✅ Native Android

📄Option 1: OpenHttpConnection API

Overview

The openHttpConnection API allows the Android client to make secure REST HTTP/HTTPS requests (GET, POST) via the REL-ID Gateway, ensuring end-to-end encrypted communication.


✅ Requirements

  • URL endpoint
  • Optional headers and body (JSON)
  • A class implementing RDNAHTTPCallbacks

🧩 Request Construction

  1. Create a RDNAHTTPRequest object
  2. Set HTTP method using RDNA_HTTP_GET or RDNA_HTTP_POST
  3. Assign the URL, headers, and body
  4. Call the openHttpConnection API

📦 Sample Code: POST Request

// Step 1: Prepare headers
HashMap<String, String> header = new HashMap<>();
header.put("Key", "Value");

// Step 2: Create RDNAHTTPRequest object
RDNA.RDNAHTTPRequest request = new RDNA.RDNAHTTPRequest(
    RDNA.RDNAHTTPMethods.RDNA_HTTP_POST,
    url,
    header,
    null // Body can be set here if needed
);

// Step 3: Invoke openHttpConnection
RDNA.RDNAStatus<Integer> status = rdnaObj.openHttpConnection(request, new RDNA.RDNAHTTPCallbacks() {
    @Override
    public int onHttpResponse(final RDNA.RDNAHTTPStatus rdnahttpStatus) {
        callOnMainThread(new Runnable() {
            @Override
            public void run() {
                // Handle UI updates or success logic
            }
        });
        return 0;
    }
});

🔁 Callback: onHttpResponse

The onHttpResponse callback is triggered once the REL-ID Gateway returns a response.

@Override
public int onHttpResponse(final RDNA.RDNAHTTPStatus rdnahttpStatus) {
    // Parse and act on the response
    return 0;
}

🛑 Error Handling

  • Always check if the returned RDNAStatus contains error codes.
  • If status.longErrorCode > 0, treat it as a failure and log/handle accordingly.

🔐 Security Note

This API provides a secure MiTM-proof channel to tunnel mobile API traffic from the app to the backend via the REL-ID Gateway. Ideal for environments where backend APIs are not publicly exposed.

📄Option 2: Proxy Interface

REL-ID SDK provides a proxy interface for native Android applications, allowing apps to tunnel REST API and WebView requests securely via a local HTTP proxy. This eliminates the need to expose backend APIs to the internet.


🔧 Initialization

Upon SDK initialization (onInitialized callback), the SDK starts a local proxy server. The port number is returned in:

response.additionalInfo.RDNAProxyPort
  • Default Port: 48080 (may vary)
  • Best Practice: Always extract port dynamically to avoid port conflicts.

🌐 Tunneling REST API Calls via Proxy

To tunnel REST API calls, use the proxy details while creating the HTTP connection.

Sample Code

int proxyPort = response.additionalInfo.RDNAProxyPort;

Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", proxyPort));
HttpURLConnection conn = new URL(urlString).openConnection(proxy);

// Continue setting headers, request method, and sending request

If you're using third-party HTTP clients (like Retrofit, OkHttp), ensure you configure the proxy via their supported methods.


🖼️ Tunneling WebView Traffic

To proxy WebView requests:

Step 1: Add ProxySetting.java to your project.

Step 2: Use the following code inside onInitialized or onUserLoggedIn callbacks:

// Parameters:
// context - Android context
// webView - your WebView instance
// proxyPort - fetched from SDK response

ProxySetting.setProxy(context, webView, "127.0.0.1", proxyPort);

This sets the WebView to route its traffic through the local SDK proxy server.


📌 Notes

  • This method is only available for Android.
  • iOS does not support proxy interface due to OS limitations.
  • Use OpenHttpConnection API as a cross-platform alternative.


✅ Cordova Plugin

📄OpenHttpConnection API for Cordova Plugin

Overview

The openHttpConnection API in the REL-ID Cordova plugin enables secure REST HTTP/HTTPS calls (GET, POST) through the REL-ID Gateway. This is particularly useful for tunneling mobile API calls from hybrid apps.


📦 API Signature

com.uniken.rdnaplugin.RdnaClient.openHttpConnection(
  function onSuccess(data) {
    // Handle success response
  },
  function onFailure(data) {
    // Handle failure response
  },
  [Enum: RDNAHttpMethods, URL, HEADER, BODY]
);

📥 Parameters

ParameterTypeDescription
RDNAHttpMethodsEnumRDNA_HTTP_GET or RDNA_HTTP_POST
URLStringHTTP/HTTPS endpoint
HEADERJSONRequest headers as JSON string
BODYJSONRequest body as JSON string (for POST only)

Both HEADER and BODY must be passed as JSON-encoded strings.


🔄 Event Listener for Response

You must listen for the onHttpResponse event for async response handling.

document.addEventListener("onHttpResponse", this.async_http_response.bind(this));

async_http_response: function (e) {
  // Handle async HTTP response
}

🧪 Example Usage

var url = "https://example.com/api/endpoint";
var headers = JSON.stringify({
  "Authorization": "Bearer token",
  "Content-Type": "application/json"
});
var body = JSON.stringify({
  "param1": "value1",
  "param2": "value2"
});

com.uniken.rdnaplugin.RdnaClient.openHttpConnection(
  function onSuccess(data) {
    console.log("Success:", data);
  },
  function onFailure(data) {
    console.error("Failure:", data);
  },
  ["RDNA_HTTP_POST", url, headers, body]
);

✅ Notes

  • Tunneling through REL-ID ensures MiTM-proof communication.
  • Make sure REL-ID SDK is initialized before invoking this API.
  • Ensure that required permissions and configurations are in place for plugin operation.

✅ React Native

📄Option 1: OpenHttpConnection API

Overview

The openHttpConnection API enables React Native apps to make secure HTTP/HTTPS calls (GET, POST) through the REL-ID Gateway.

Usage

  • Import the module and method enum:
import RdnaClient, { RDNAHttpMethods } from 'react-native-rdna-client';
  • Prepare headers and body as JSON:
var postData = {
  "Param1": "value1",
  "Param2": "value2"
};
  • Invoke the API:
RdnaClient.openHttpConnection(
  RDNAHttpMethods.RDNA_HTTP_POST,
  baseUrl,
  contentType,
  postData,
  (response) => {
    // Handle HTTP response or error JSON
  }
);

Make sure to use valid method types: RDNA_HTTP_GET, RDNA_HTTP_POST


📄Option 2: Proxy Interface (Android)

This allows both WebView and REST API requests to be tunneled through a local proxy set up by the REL-ID SDK.

📍 WebView Tunneling

Step 1: Add ProxySetting.java to your Android project.

Step 2: Set Proxy in onInitialized callback

ReactRdna.setProxy(webViewTag, "127.0.0.1", proxyPort).then((value) => {
  if (value) {
    // Proxy set successfully
  }
});

Step 3: Update Proxy on onUserLoggedIn for session-based tunneling.


📡 REST API Tunneling using Proxy

Step 1: Add RDNARequestUtility.java to Android native module and expose it via RDNAReactPackage.

public class RDNAReactPackage implements ReactPackage {
  @Override
  public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
    List<NativeModule> modules = new ArrayList<>();
    modules.add(new ReactRdnaModule(reactContext));
    modules.add(new RDNARequestUtility(reactContext));
    return modules;
  }
}

Step 2: Import native module in JS

const RDNARequestUtility = require('react-native').NativeModules.RDNARequestUtility;

Step 3: Set proxy using proxy port

RDNARequestUtility.setHttpProxyHost('127.0.0.1', proxyPort, (response) => { });

Step 4: Make GET request

RDNARequestUtility.doHTTPGetRequest(URL, (response) => {
  // Handle GET response
});

Step 5: Make POST request

var userMap = { "Key": "value" };

RDNARequestUtility.doHTTPPostRequest(URL, userMap, (response) => {
  // Handle POST response
});

React Native tunneling supports both secure REST communication and WebView proxy-based redirection through REL-ID Gateway.


🧭 When to Use Tunneling?

Use REL-ID Tunneling if:

  • Backend APIs are not exposed on public internet
  • You want a secure, encrypted path for API traffic
  • You're implementing zero trust architecture