VRED comes with an integrated web server, which offers a Python API, Web API, and low latency video streaming. The Web API is a remote procedure call API (RPC API) and it is build on the same base as the Python API v2 and is accessible via JavaScript. Since it supports the same functions and parameters, please use the documentation for the Python API v2.
The advantage of the Web API over the Python API is that it is easier to use and integrate into web applications. In addition, the Web API supports event-listeners (signals in Python) that inform the client about changes in realtime.
The Web API endpoint is {schema}://{host}:{port}/api/{module}/{procedure}
.
For example, this is a URI to connect to a local instance using TLS:
http://localhost:8888/api/vrAnnotationService/getAnnotations
VRED comes with an integrated JavaScript client library that can be easily integrated into a website or app.
The client library is available at {schema}://{host}:{port}/api.js
.
For example:
http://localhost:8888/api.js
The base URL can be changed if the client lib is loaded from an origin other than the VRED web server:
api.setBaseUrl(`${schema}://${host}:${port}`);
A simple example on how to use the client lib can be found below. More examples will be shipped with VRED and can be found in the Examples folder.
import { api } from 'http://localhost:8888/api.js';
// Connect event listener (signal)
api.vrAnnotationService.annotationsAdded.connect(() => console.log('Annotations added'));
// Add a new annotation
api.vrAnnotationService.createAnnotation('Annotation1')
.then(() => {
api.vrAnnotationService.findAnnotation('Annotation1')
.then(a => a.setText('Lorem ipsum'));
})
.catch(() => console.error('Add annotation failed'));
// Get all annotations
api.vrAnnotationService.getAnnotations()
.then(annotations => annotations.forEach(a => console.log(a)))
.catch(() => console.error('Get annotations failed'));
Additionally, VRED offers an OpenAPI specification for the Web API that can be used with Swagger UI and other useful API tools.
The specification is available at {schema}://{host}:{port}/api.json
.
For example:
http://localhost:8888/api.json