API endpoints with sockets
API calls exceeding one minute will result in a timeout. To address this, we have introduced a socket connection mechanism.
Here's the refined explanation of the process:
- Client Initiation: To begin, the client initiates a room specifically designated for the given tenant-ID and project-ID.
- API Request Dispatch: The client proceeds to dispatch the API request to the server. This request, importantly, promptly concludes without delay.
- 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 how to retrieve the generated information.
- Data Retrieval: The client, now informed by the server via the socket, proceeds to download the generated content. Once this operation is successfully completed, the client gracefully exits the designated room.
Supported API calls
Refer to the API documentation that is released with your server.
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 |
|
|
|
|

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
C#
This example below shows C# pseudo-code and uses the
SocketIOClient. It contains of 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