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 and registering an example Endpoint
Create a Script Machine on the GameObject of preference. Usually a GameObject that is controlled by the rest call.
Open the Graph and create a Rest Server Reference Node that is called On Start
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).
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 follows the same pattern: Create a Endpoint Definition node and make sure it’s after the Rest Server Reference node.
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.
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.
The event node is called every time a request is received. In this example we send back a simple “OK” to the caller.
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.