VRisingServerApiPlugin 0.1.7

dotnet add package VRisingServerApiPlugin --version 0.1.7                
NuGet\Install-Package VRisingServerApiPlugin -Version 0.1.7                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="VRisingServerApiPlugin" Version="0.1.7" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add VRisingServerApiPlugin --version 0.1.7                
#r "nuget: VRisingServerApiPlugin, 0.1.7"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install VRisingServerApiPlugin as a Cake Addin
#addin nuget:?package=VRisingServerApiPlugin&version=0.1.7

// Install VRisingServerApiPlugin as a Cake Tool
#tool nuget:?package=VRisingServerApiPlugin&version=0.1.7                

VRisingServerApiPlugin

<p align="center"> <img src="https://github.com/hermesdj/VRisingServerApiPlugin/raw/dev/images/logo_256.png" /> </p>

VRising Server API used to expose new HTTP Routes

Configuring the server

In the ServerHostSettings.json file of the VRising server, you have to activate the API :

{
  "API": {
    "Enabled": true,
    "BindAddress": "*",
    "BindPort": 9090,
    "BasePath": "/",
    "AccessList": "",
    "PrometheusDelay": 30
  }
}

Then, you have to put the DLL of this plugin in the plugins directory of the BepInEx folder on your server. In the logs, you will be able to see the new routes created. You can then call the routes using another program or something like Postman to query the available endpoints.

How it works

You can find two working examples on how the endpoints are exposed through the VRising Server HTTP API in the endpoints folder of the project. I have implemented a few basic GET and POST methods for two endpoints : clans and players

The API is capable of parsing url params, query params and JSON Bodies. Only JSON bodies are supported and the Content-Type=application/json must be present in the header of the HTTP request.

For url params, I am using regex groups to match by name.

For the endpoint /players/:id where id is an integer that match a userIndex in the game, the endpoint is declared the following way :

[HttpGet("/(?<id>[0-9]*)")]
public PlayerApiResponse GetPlayerDetails([UrlParam("id")] int userIndex)

The regex use a group called id that match any number, and it is mapped to the userIndex parameter of the method by using the "id" param name.

The plugin will try to cast the url params, query params and request body to the parameter type of the method. See for example the update clan name method :

[HttpPost(@"/(?<id>[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12})/updateName")]
public GetClanResponse UpdateClanName([UrlParam("id")] Guid clanId, [RequestBody] UpdateClanNameBody? body)

The url param id is parsed as a Guid, and the RequestBody is used as the base class to deserialize the JSON of the body received. The regex used in the HttpPost definition is a regex that match an uuid.

Using the plugin as a dependency

The CommandRegistry expose a public method RegisterAll. Import the DLL of the project as a dependency to your own plugin, then declare some API endpoints using the Attributes declarations explained above, and then call the following method to register your assembly :

CommandRegistry.RegisterAll();

Thanks

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on VRisingServerApiPlugin:

Package Downloads
VRisingApiWebHooks

Created with VRising.ModTemplate, you should edit this.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.1.7 125 6/15/2023
0.1.6 110 6/14/2023
0.1.5 99 6/14/2023
0.1.4 99 6/13/2023
0.1.3 100 6/13/2023
0.1.2 99 6/13/2023
0.1.1 97 6/13/2023
0.1.0 93 6/13/2023
0.1.0-prod.1 84 6/13/2023