Examples

Usage 1.4.0

The examples have been included in the package and are imported when the Rest Server package is installed. They can be found in the package directory (usually de.bearo.restserver) in the subdirectory Samples.

Usage before 1.4.0

The basic usage example can be downloaded here. How to run:

  • Download the zip file and extract it.
  • Open the restserver-basicusage directory with Unity.
  • “Enter Safe Mode?” - Ignore the compilation errors and open the project.
  • Import the “RestServer” package via the package manager.
  • All compilation errors should be fixed.
  • Open the SampleScene.
  • Read the “README.md” file.

Example Description

Note: In all examples the Http Methods are not chosen according to the REST standard or best practices, just for ease of use for the user.

Simple REST Server Example

Simple REST Server usage. This example has the following endpoints

  • GET /position:
    • Returns the current position of the Cube (rest controlled) game object: {"x":0, "y":0, "z":0}
    • If a query parameter is given, like http://localhost:8080/position?x=3&y=-2, then the Game object is moved to that position
  • POST /position:
    • Accepts json in the form {"x":0, "y":0, "z":0} and sets the position of the Cube (rest controlled) game object to the given one. Missing coordinates will be interpreted as zero.
  • GET /triggeranimation:
    • Moves the game object Cube (rest controlled) on the positive x-axis over 10 seconds.

Stream Deck 1.4.0

This shows how Unity can be easily controlled with a Stream Deck (or similar). The Stream Deck has a built-in method to call GET endpoints (System -> Webpage, check “Get request in background”). This example has the following endpoint:

Twitch Overlay 1.4.0

This shows how a Twitch Overlay for OBS (or similar apps) can be done. The background is a uniform color, that can be removed in OBS. The scene could easily be controlled via a Stream Deck. This example has the following endpoint:

  • GET /new_follower:
    • Shows the text “New Follower!” for 5 seconds

Simple VS Example (Visual Scripting) 1.4.0

This shows how visual scripting can be used. The background is a uniform color, that can be removed in OBS. The scene could easily be controlled via a Stream Deck. This example has been created with visual scripting and exposes the following endpoint:

  • GET /move:
    • Changes the material of the game object and moves it around randomly.

Interlock Example 1.4.0

Shows the usage of the new SimpleInterlock class, which helps implementations where repeated requests against the same endpoint do not restart a animation while it’s running.

  • GET /move:
    • Changes the material of the game object and moves it around randomly.

Binary Example 1.4.0

Shows the implementation of an endpoint which let the user download an image

  • GET /image:
    • Displays the image of a Nyan cat