Auto Endpoints

Auto endpoints are ready to use endpoint implementations that allow the user to easily configure an endpoint in the inspector without using C#.


Transform Auto Endpoint

Provides an endpoint implementation to update scaling/rotation and position of the given Game Object.

Options:

  • Rest Server: Reference to the rest server to register to. Can be left empty if the rest server component is on the same game object.
  • Target: The object that is modified. If left empty, the game object the component is registered on.
  • Endpoint Path: The endpoint path that accepts requests to retrieve or update scaling/rotation and/or position.

The following HTTP methods are understood by the implementation:

  • GET: Retrieves the current information from the Game Object.
  • POST: Overwrite the current information on the Game Object with the ones supplied from the request. Every field from the json not supplied in the request, will have it’s default value (usually 0).
  • PATCH: Update the current information on the Game Object with the information from the request. Fields not supplied in the json will retrain their current value.

The endpoint understands the following json format and also accepts the same json to update the referenced Game Object:

{
  "position": {
    "x": 0.0,
    "y": 0.0,
    "z": 0.0
  },
  "rotation": {
    "x": 0.0,
    "y": 0.0,
    "z": 0.0
  },
  "scale": {
    "x": 1.0,
    "y": 1.0,
    "z": 1.0
  }
}

Method (V2) Auto Endpoint

Endpoint implementation that simplifies the registering of methods via the Unity inspector.

Options:

  • Rest Server: Reference to the rest server to register to. Can be left empty if the rest server component is on the same game object.
  • Endpoint Path: The path under which all endpoints added to this component are registered to be accessed.

Options for each endpoint:

  • Sub Path: Path under which this content is reachable. Added to the Root Path to get the final path.
  • Method: Http method the callee is executed when the rest server is called
    • The method implementation should have the signature void Method(RestRequest) to gain access to the complete functionality
  • Callee: Method on a specific game object that is executed when the rest server receives a request on the defined endpoint and method.
    • The method implementation should have the signature void Method(RestRequest) to gain access to the complete functionality

Attribute Auto Endpoint

The attribute auto endpoint allows to define endpoints with attributes on methods. For example:

[Endpoint("/get")]
public void Endpoint_Get(RestRequest r) {
  // ...
}

For this to work the method(s) attributed must be defined on MonoBehaviours which are attached to GameObjects in the active scene. The attribute auto endpoint can inspect all GameObjects in the current scene, or only the registered game objects.

This GameObjects are only inspected once when loading the scene or activating the auto endpoint. After the initial scan is done, there is no automatic update. Any changes to the scene (ex: creating / deleting of GameObject) must be handled by the user by triggering a re-scan. A re-scan is triggered by deactivating and then re-activating the auto endpoint component. Note that deactivating will remove all previously registered endpoints from the server.

Since iterating through game objects and components is costly, it is only done once and upon request.

Options:

  • Rest Server: Reference to the rest server to register to. Can be left empty if the rest server component is on the same game object.
  • Root Path: The path under which all assets added to this component are registered to be accessed.
  • Inspect complete scene:
    • true: Iterates on scene load over all loaded GameObjects that are in the scene and scans every registered component (both active and deactivated) for instances of the Endpoint attribute
    • false: Only iterates the specified GameObjects and their registered components for instances of the Endpoint attribute.

Endpoint Attribute Options:

  • Sub Path: Path under which this content is reachable. Added to the Root Path to get the final path.
  • Method: Http method the callee is executed when the rest server is called
  • Synchronize: If set to true, the method is executed on the main thread. If set to false, the method is executed on a background thread.
    • If set to true, calls to ThreadingHelper aren’t allowed and will produce an error, because the method is already executed on the main thread.
    • If set to false, calls to ThreadingHelper are required to access Unity objects, because the method is executed on a background thread.
  • IsRegex: The sub path is to be treated as regex and will be added to the Root Path.

Material Auto Endpoint

This endpoint allows you to expose materials via rest for querying and modification. Each property that should be exposed has to be configured on the auto endpoint with the shader property. The names of shader properties can be viewed in the inspector when inspecting the shader the material is based on (usually by pressing the “Edit” button when viewing the material beside the shader selector)

Options:

  • Rest Server: Reference to the rest server to register to. Can be left empty if the rest server component is on the same game object.
  • Endpoint Path: The path under which all endpoints added to this component are registered to be accessed.
  • Exposed property names: Unity shader properties to expose to the REST interface. The property names have to start with “_” and can be viewed when inspecting a shader in the Unity inspector.

Static Content Auto Endpoint

Helps with serving static content, like JavaScript, HTML, CSS and other file types, directly from the inspector without custom coding.

Options:

  • Rest Server: Reference to the rest server to register to. Can be left empty if the rest server component is on the same game object.
  • Root Path: The path under which all assets added to this component are registered to be accessed.
  • Map index Html: If set registers content, that ends with index.htm or index.html, under the directory path /.
  • Use Coroutine Init: If set asynchronously registers the content incremental after startup. If unset all content will be extracted and registered when the scene is loaded.
  • Debug Log: Give more information when registering content to the rest server.

Options for Files:

  • Sub Path: Path under which this content is reachable. Added to the Root Path to get the final path.
  • Extract Zip: Switches this entry to zip mode, see below.
  • Asset: Reference to the unity asset to serve.
  • Handle as binary?: If set the asset is read using the binary Unity Asset API. Use with images or other binary content and make sure that the asset is named .bytes
  • Content Type: The Content-Type header to send to the caller when this file is delivered

Options for Zip Files:

The static content auto endpoint can dynamically extract zip files and deliver the contents. This is useful for delivering JavaScript applications, for example.

  • Sub Path: Path under which this content is reachable. Added to the Root Path to get the final path. Every file from the zip will be under this sub path.
  • Extract Zip: Has to be enabled for zip extraction mode.
  • Asset: Reference to the zip file asset to extract.

StreamingAssets Auto Endpoint / WebServer

StreamingAssets allow to raw include files into the Unity build and therefore is ideal for including static content like HTML, CSS, JavaScript and other files. All files in the /Assets/StreamingAssets folder (case-sensitive) are included in the build and can be accessed by the auto endpoint.

Options:

  • Rest Server: Reference to the rest server to register to. Can be left empty if the rest server component is on the same game object.
  • Endpoint Path: The path under which all files are served (the client has to call http://server:port/endpoint_path/...)
  • Streaming Assets Sub Folder: The path to the files inside the streaming assets folder. All files under this paths are served automagically
  • Map index Html: If set registers content, that ends with index.htm or index.html, under the directory path /.
  • Try Files: Files which should be served when the client accesses a folder directly (e.g. http://server:port/endpoint_path/).
    • The first file that is found is served.
  • Background Request Timeout: Android only: Timeout for the request to wait at maximum until the file is extracted from the APK.

When a request path can’t be found inside the StreamingAssets folder, the request is forwarded to other endpoints inside the rest server. This makes it possible to register custom endpoints alongside the static content.