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.
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
:This example shows how a web view could use the rest server as backend api in mobile applications (iOS and Android).
Here it’s shown with the UniWebView, but can be used with any other web view as well. To use the UniWebView the
package needs to be installed in the current project and the file ExampleUWVController.cs
needs to be updated by
removing the first #define
in the file.
If no UniWebView is available, and the #define
is commented, the rest server can still be accessed via a normal
web browser.
Please be aware of the code in the ExampleUWVController.cs
file and its comments when you want to implement something
like this in production.
This example shows how rest servers could be discovered using mDNS. This can be used for mobile devices in course settings (for example for VR headsets). The advertisements of mDNS hosts and the discovery is not instant and needs some time to propagate, it is also very network dependent. Which means that the network must support multicast udp packets. Most home networks do support these, but almost all enterprise networks do not (due to security). Another thing to consider is network “breaks”, for example cable network and wireless networks are usually separated and the hardware used needs to be configured and support multicast udp packets.
If you want to use this in production, please consider the above points and test it thoroughly. For example, if used in a training setup with VR headsets, it may be a good option to bring your own custom network hardware to be safe.
This example shows how an application could log in via itch.io OAuth variant to allow API access. This could be used to enable DLC or purchase proofs among other use cases.
See the video on how to setup and use the example.
This shows an implementation for the OAuth Auth Code Flow where the user can log in a remote application for additional features or to access a remote API (Twitch, Patreon and others). This example implementation is shown with the open source Keycloak server. Any other OAuth Auth Code compatible server could be used.
See the video on how to setup and use the example.