Assets/_Molca/_Core/Networking/Http/HttpClient.csAssets/_Molca/_Core/Networking/Http/HttpRequestAsset.cs
When to use
HttpRequestAsset(recommended) — for data-driven endpoints where URL, method, headers, and body templates live in a ScriptableObject. Best for stable API calls configured once in the Inspector.HttpRequestBuilder(programmatic) — for dynamic endpoints or when URL/body must be built at runtime. Uses a fluent builder API.- Both route through the same
HttpClientsubsystem with queuing, concurrency control, and connection error events.
HttpClient
RuntimeSubsystem — async HTTP with request queuing, auth header management, and event hooks.
| Method | Signature | Description |
|---|---|---|
SendAsync | static async Awaitable<HttpResponse> SendAsync(HttpRequest request) | Send request and await response |
Send | static void Send(HttpRequest req, Action<HttpResponse> onSuccess, Action<string> onError, Action<float> onProgress) | Callback-style send |
CreateRequest | static HttpRequestBuilder CreateRequest() | Start a fluent builder chain |
AddDefaultHeader | static void AddDefaultHeader(string key, string value) | Add header to all future requests |
RemoveDefaultHeader | static void RemoveDefaultHeader(string key) | Remove a default header |
CancelAllRequests | static void CancelAllRequests() | Abort all active requests |
OnRequestStarted, OnRequestCompleted, OnRequestFailed, OnConnectionError (static event Action).
Properties: BaseUrl, MaxConcurrentRequests, ActiveRequestCount, RequestHistory.
HttpRequestAsset
ScriptableObject describing URL, method, headers, and body templates. Create via Molca → Networking → HTTP Request.| Method | Signature | Description |
|---|---|---|
SendAsync | async Awaitable<HttpResponse> SendAsync() | Send this asset’s configured request |
Send | void Send(Action<HttpResponse> onSuccess, Action<string> onError, Action<float> onProgress) | Callback-style send |
CreateBuilder | HttpRequestBuilder CreateBuilder() | Clone into a builder for runtime modifications |
Validate | bool Validate(out string[] errors) | Check configuration before sending |
Code
From aHttpRequestAsset (recommended when the request is mostly data-driven):
Troubleshooting
- Request fails silently: subscribe to
HttpClient.OnRequestFailedorOnConnectionErrorfor diagnostics. The request may have been queued but not started ifMaxConcurrentRequestsis exceeded. - Auth header missing on requests: call
HttpClient.AddDefaultHeader("Authorization", "Bearer " + token)after login. Default headers are applied to all future requests automatically. - Wrong base URL:
BaseUrlcomes fromHttpModuleon Global Settings. If the module is missing, URLs must be absolute (setuseFullUrl = trueor useFullUrl()on the builder). - Request validation fails:
HttpRequestAsset.Validate(out errors)will returnfalseif the URL is empty or malformed. Check theerrorsarray for specifics.
Related
- DataManager — for persistent data providers rather than one-off requests
- Scenario network config — VR session HTTP endpoints
- Global Settings —
HttpModulebase URL and defaults
Unity Editor
Select an HttpRequestAsset under Scriptable Objects / Http Request (or your project folder).
