com.mostajs.netclient
v0.1.0
Published
Unity package — talks to @mostajs/net servers. Shares the wire contract with the .NET / Java / Python / TS ports. Works on Mono/IL2CPP, Standalone, iOS, Android, WebGL (via UnityWebRequest fallback).
Downloads
177
Maintainers
Readme
@mostajs/net — Unity client (UPM package)
Auteur : Dr Hamid MADANI [email protected] Licence : AGPL-3.0-or-later + licence commerciale disponible UPM name :
com.mostajs.netclient:0.1.0Target : Unity 2020.3 LTS and up — Mono & IL2CPP, Standalone, iOS, Android, WebGL
Unity-native client for @mostajs/net.
Two flavours are available to you inside a Unity project :
| Layer | File(s) | When to use |
|---|---|---|
| Vanilla .NET (HttpClient) | Drop MostaJs.Net.Client.dll (netstandard2.0) into Assets/Plugins/ | Standalone, mobile (Mono/IL2CPP). Idiomatic async/await — same API as the NuGet package |
| Unity-specific (UnityWebRequest) | Shipped here as UnityWebRequestNetClient.cs | WebGL (HttpClient cannot block the main thread), or any code path where you prefer coroutines |
Install
Option A — Package Manager (OpenUPM-style)
Window → Package Manager → + → Add package from git URL
→ https://github.com/apolocine/mosta-net-client-unity.gitOption B — Manual UPM
Edit Packages/manifest.json :
{
"dependencies": {
"com.mostajs.netclient": "https://github.com/apolocine/mosta-net-client-unity.git#0.1.0"
}
}Option C — DLL only (for HttpClient-based API)
Download MostaJs.Net.Client.0.1.0.nupkg from NuGet, extract the
lib/netstandard2.0/MostaJs.Net.Client.dll, drop it into
Assets/Plugins/ of your Unity project.
Quick start — coroutine (WebGL safe)
using UnityEngine;
using MostaJs.Net.Client.Unity;
public class Demo : MonoBehaviour
{
private UnityWebRequestNetClient _net;
private void Start()
{
_net = new UnityWebRequestNetClient("http://localhost:4488", "sk_dev_local");
StartCoroutine(_net.Health((ok, err) => Debug.Log($"reachable: {ok}")));
StartCoroutine(_net.FindAll("User", null, (body, err) =>
{
if (err != null) Debug.LogError(err);
else Debug.Log($"users: {body}");
}));
}
}(See the Quick Start sample : Window → Package Manager →
MostaJs Net Client → Samples → Import.)
Quick start — async/await (Standalone, mobile only)
On IL2CPP / Mono Standalone platforms you can use the vanilla .NET client bundled as the plugin DLL :
using MostaJs.Net.Client;
async void Start()
{
using var net = NetClient.Create()
.UrlOf("http://localhost:4488")
.WithApiKey("sk_dev_local")
.Build();
if (await net.HealthAsync())
{
var users = await net.FindAllAsync<Dictionary<string, object>>("User");
Debug.Log($"loaded {users.Count} users");
}
}Same signatures as in the C# README
(../mosta-net-client-dotnet/README.md). The only difference on Unity :
avoid it on WebGL builds — use UnityWebRequestNetClient instead.
Schema registration
Same 6-step flow as every port. With coroutines :
IEnumerator RegisterUserSchema()
{
var net = new UnityWebRequestNetClient(serverUrl, apiKey);
yield return net.Health((ok, err) => { /* verify */ });
var schemaJson = @"{""schemas"":[{""name"":""User"",""collection"":""users"",
""timestamps"":true,
""fields"":{""email"":{""type"":""string"",""required"":true}}}]}";
yield return net.UploadSchemasJson(schemaJson, (body, err) =>
{
Debug.Log($"upload result: {body}");
});
// After the server's self-restart (~2-5 s), poll /health + /api/schemas-config
// until the entity appears. In Unity you'd do it with a while + yield return
// new WaitForSeconds(1).
}For the complete flow diagram and pitfalls see
Entreprise/multi-runtime/SUIVI-PORTS-POLYGLOTTES-20260424.md §3.
API surface (UnityWebRequest flavour)
Every method is a coroutine (IEnumerator) that yields the HTTP call
and invokes a NetCallback<T> when done.
| Method | Callback payload |
|---|---|
| Health(cb) | bool ok |
| FindAll(collection, filterJson, cb) | string rawJsonBody |
| FindById(collection, id, cb) | string rawJson (null on 404) |
| Create(collection, jsonBody, cb) | string rawJson |
| Update(collection, id, jsonBody, cb) | string rawJson |
| Delete(collection, id, cb) | bool ok (false on 404) |
| GetSchemasConfig(cb) | string rawJson |
| UploadSchemasJson(schemasJsonBody, cb) | string rawJson |
All bodies are returned as raw JSON string — use JsonUtility,
Newtonsoft.Json or System.Text.Json to deserialise.
Why two flavours ?
HttpClient on Unity :
- ✅ Works on Standalone, Mono desktop, IL2CPP mobile
- ❌ Blocks or throws on WebGL (main-thread constraints of the browser)
- ⚠️ Requires
.NET Standard 2.1mode or later versions of the API Compatibility Level
UnityWebRequest :
- ✅ Works everywhere Unity builds — including WebGL, Consoles, XR
- ✅ Coroutine-friendly, integrates naturally with
StartCoroutine - ❌ Slightly more verbose than async/await
- ❌ No built-in cancellation beyond stopping the coroutine
If in doubt, use UnityWebRequestNetClient — it is guaranteed to
compile on every Unity target.
Relation to the @mostajs ecosystem
Unity joins the family alongside the vanilla .NET (NuGet) port and shares the same wire contract.
Node / TS Java C#/.NET Delphi Python Go Swift Kotlin Dart
│ │ │ │ │ │ │ │ │
└──────────┴────────┴─────────┴────────┴─────┴─────┴────────┴────────┘
│
▼
@mostajs/net — shared wire contract
│
▼
Unity ◀── this packageLicence
AGPL-3.0-or-later. Commercial licensing : [email protected].
