Skip to main content

Rigi Documentation

API endpoints with sockets

API calls exceeding one minute will result in a timeout. To address this, we have introduced a socket connection mechanism working the following way:

  1. Client Initiation. A client initiates a room designated for the given tenant ID and project ID.

  2. API Request Dispatch. The client proceeds to dispatch the API request to the server. What is important is that this request is promptly concluded without delay.

  3. Server Processing. Upon receiving the request, the server begins processing the request to generate the desired content. As soon as this task is completed, the server communicates via the socket to provide instructions on retrieving the generated information.

  4. Data Retrieval. The client, now informed by the server via the socket, downloads the generated content. Once this operation is successfully completed, the client leaves the designated room.

Supported API calls

Refer to the API documentation that was released with your server.

Table 15.

Endpoint

Join room

event name

Event to connect

Leave room

event name

/api/projects/{projectId}/process/targets

joinProcessRoom

process_export_target

leaveProcessRoom

/api/projects/{projectId}/process/sources

joinProcessRoom

process_export_source

leaveProcessRoom

/api/projects/{projectId}/process/pseudo

joinProcessRoom

process_export_pseudo

leaveProcessRoom


The returnZip query parameter

The process API calls support a synchronous version (i.e., no use of sockets).

Setting the query parameter returnZip for these calls to true will return the ZIP file.

Sample code

The example below shows the C# pseudo-code and uses the SocketIOClient. It contains a RigiSocket class and shows how to use it.

using SocketIOClient;
using System;
using System.Dynamic;
using System.Text.Json;
using System.Threading;
public class RigiSocket
{  
   public RigiSocket(...)
   {
      dynamic dynamicObject = new ExpandoObject();
      dynamicObject.token = <token>>;
      dynamicObject.withCredentials = true;
      SocketIOOptions options = new SocketIOOptions
      {
        Auth = dynamicObject,
        Transport = SocketIOClient.Transport.TransportProtocol.WebSocket
      };
      _client = new SocketIOClient.SocketIO("https://<servername>.rigi.io", options);
      _client.OnConnected += async (sender, e) =>
      {
        dynamic enterRoomObject = new ExpandoObject();
        enterRoomObject.projectId = <projectId>;
        enterRoomObject.tenantId = <servername>_rigi_io; //Same as the server name, where dots are replaced with underscores
        await _client.EmitAsync(<enterRoomEventName>, enterRoomObject);
      };
      _client.On(downloadReadyEvent, response =>
      {
        //The response was received from the server with the download id.
        try
        {
          using (JsonDocument doc = JsonDocument.Parse(response.ToString()))
          {
            JsonElement root = doc.RootElement;
            _downloadId = root[0].GetProperty("downloadId").GetString();
          }
        }
        catch(Exception e)
        {
          _downloadId = $"ERROR: {e.Message}";
        }
      });
      _client.ConnectAsync().GetAwaiter().GetResult();
    }
   private void LeaveRoom()
    {
      _client.EmitAsync(<leaveRoomEventName>, _projectId).GetAwaiter().GetResult();
    }
    public static string WaitForDownload(RigiSocket socket, int intervalMs=1000)
    {
      while (socket._downloadId == null)
        Thread.Sleep(intervalMs);
      socket.LeaveRoom();
      int id;
      if (!int.TryParse(socket._downloadId, out id))
      {
        Console.WriteLine(socket._downloadId); //The download was not successful (the download ID contains the error message)
        return null;
      }
      return socket._downloadId;
    }
  }
}

The main program that uses the socket looks like this:

var socket = new RigiSocket(...);
api.execute("api/process/targets", targetfolder, ...);
string zipId = RigiSocket.WaitForDownload(socket);
string generated = pseudoTask.DownloadZipId(zipId); //The ZIP is now in the target folder