Overview 1.4.0

To use the Rest Server from Visual Scripting the following steps are needed

  • Referencing the Rest Server GameObject
  • Registering an Endpoint
  • Creating the nodes that are executed on each rest call

Referencing the Rest Server GameObject

Create a Script Machine on the GameObject of preference. Usually a GameObject that is controlled by the rest call.

Add the Script Machine Component

Open the Graph and create a Rest Server Reference Node that is called On Start

Create Rest Server Reference Node

Pull the GameObject from the Hierarchy into the scene, which has the Rest Server component (See install on how to set up if it doesn’t exist in the scene.) and select the Game Object itself (here it’s called SERVER).

Pull the Server Game Object into the scene and a pop menu opens.

Connect up the Game Object with the Node Rest Server Reference. Now every node behind the Rest Server Reference has a connection to the Rest Server and doesn’t need any additional information. There should only be one Rest Server Reference in the execution path, otherwise later references will overwrite the previous ones.

Registering an Endpoint

Registering an endpoint follows the same pattern: Create a Endpoint Definition node and make sure it’s after the Rest Server Reference node.

Create endpoint definition after the rest server reference.

The Endpoint Definition specifies which endpoint to create. Here we are listening on GET requests on http://localhost:8080/. Note: The “Not Request Trigger” execution thread is not called when a request is received. Here additional Endpoint Definition can be connected.

Endpoint Definition.

Next add the Incoming Rest Request Event node to handle incoming rest requests to the previous defined endpoint. The Incoming Rest Request Event can be more easily chosen, when using the search.

Adding Incoming Rest Request Event node.

The event node is called every time a request is received. In this example we send back a simple “OK” to the caller.

Send a response back.

Every request needs to be terminated with a Send Response Node. If a request is not terminated with a Send Response Node, or takes longer than 2000ms to execute, the caller will receive an Internal Server Error (500) Response. The timeout can be adjusted in the Endpoint Definition Node.

Enter Playmode and call http://localhost:8080/. The Browser should show “OK”.