Headless (no viewer) frontend examples #8132
Replies: 1 comment
-
|
Hi Ryan, Great question; excited to see what you build. You will first need to initialize IModelApp and since its a headless app I recommend using NoRenderApp. iTwin.js uses RPC for its communication, so you will need to establish a connection via BentleyCloudRpcManager and use the Re auth: Here's a some sample code you can use for reference: const iTwinId = 'YOUR_ITWIN_ID';
const iModelId = 'YOUR_IMODEL_ID';
const rpcInterfaces = [IModelReadRpcInterface];
await NoRenderApp.startup({
authorizationClient: {
getAccessToken: async () =>
'Bearer abc...def',
},
rpcInterfaces,
hubAccess: new FrontendIModelsAccess(),
});
const cloudRpcParams: BentleyCloudRpcParams = {
info: { title: 'imodel/rpc', version: '' },
uriPrefix: 'https://api.bentley.com',
};
BentleyCloudRpcManager.initializeClient(cloudRpcParams, rpcInterfaces);
const iModelConn = await CheckpointConnection.openRemote(iTwinId, iModelId); |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm using Cesium along with the Mesh Export API to visualise an iModel, rather than the default iTwin viewer.
I would still like to use iTwin.js and ECSQL to query my iModel's metadata in various ways.
Are there any examples that demonstrate a headless way to authenticate and connect with an iModel from a frontend application for this purpose? Most samples I can find are either based on the viewer or backend services.
EDIT: Another follow up question - if I already have an Authorization (bearer) token that hasn't expired, is there a way for me to set this somewhere directly so I don't need to implement the full auth process with redirects etc?
I'm just trying to experiment within some very simple vanilla typescript code.
Beta Was this translation helpful? Give feedback.
All reactions