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.
The basic usage example can be downloaded here. How to run:
restserver-basicusage
directory with Unity.Ignore
the compilation errors and open the project.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 usage. This example has the following endpoints
/position
:{"x":0, "y":0, "z":0}
/position
:{"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./triggeranimation
: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:
/spawn
:/spawnMultiple
: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:
/new_follower
: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:
/move
: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.
With Disable Interlock
the effects without the Interlock class can be experienced and how the animation can be
made look broken.
/move
:Shows the implementation of an endpoint which let the user download an image
/image
:The static content example shows a simple angular application that is served using the rest server (compressed in the sample-app.zip). The app allows to show/hide a cube. Note that the app is shared with the websocket example and the websocket buttons/text is not working in this example.
/
(and more):sample-app.zip
. To aid navigation, every path that can’t be found will be redirected to the main /index.html
./static/
:This example implements a reverse proxy. In this case it reverse proxies this documentation pages.
/.*
:This example shows a simple form upload (multipart/form-data) upload by using a simple, custom parser.
/
:/upload
:Simple example showing the basic usage of a websocket. The websocket delivers the current position of the cube. The static content auto endpoint is used to serve a simple angular web application that connects to the websocket. Note that the app is re-used from the static content example and only the websocket part is working.
/
:/websocket/cube_updates
: