Documentation Index
Fetch the complete documentation index at: https://docs-unity.molca.id/llms.txt
Use this file to discover all available pages before exploring further.
Files:
Assets/_Molca/_Core/Networking/Http/HttpClient.cs
Assets/_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
HttpClient subsystem 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 |
Events: 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 a HttpRequestAsset (recommended when the request is mostly data-driven):
using Molca.Networking.Http;
using UnityEngine;
public class ProfileClient : MonoBehaviour
{
[SerializeField] private HttpRequestAsset fetchProfile;
private async void Start()
{
await RuntimeManager.WaitForInitialization();
var response = await fetchProfile.SendAsync();
if (response.IsSuccess)
Debug.Log(response.Text);
}
}
Programmatic requests using the fluent builder:
using Molca.Networking.Http;
using UnityEngine;
public class DynamicApiClient : MonoBehaviour
{
private async void FetchUser(int userId)
{
var response = await HttpClient.CreateRequest()
.Method(HttpMethod.GET)
.Url($"/api/users/{userId}")
.Header("Accept", "application/json")
.Timeout(10)
.SendAsync();
if (response.isSuccess)
Debug.Log(response.Text);
else
Debug.LogError(response.errorMessage);
}
}
API Reference
HttpClient
| 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 |
Events: OnRequestStarted, OnRequestCompleted, OnRequestFailed, OnConnectionError (static event Action).
Properties: BaseUrl, MaxConcurrentRequests, ActiveRequestCount, RequestHistory.
HttpRequestAsset
| 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 |
HttpRequestBuilder
| Method | Signature | Description |
|---|
Method | HttpRequestBuilder Method(HttpMethod method) | Set HTTP method (GET, POST, PUT, DELETE) |
Url | HttpRequestBuilder Url(string url) | Set relative or absolute URL |
FullUrl | HttpRequestBuilder FullUrl(string url) | Set absolute URL, bypassing BaseUrl |
Header | HttpRequestBuilder Header(string key, string value) | Add a request header |
Body | HttpRequestBuilder Body(string body) | Set request body content |
Timeout | HttpRequestBuilder Timeout(int seconds) | Set request timeout |
SendAsync | async Awaitable<HttpResponse> SendAsync() | Build and send the request |
Troubleshooting
- Request fails silently: subscribe to
HttpClient.OnRequestFailed or OnConnectionError for diagnostics. The request may have been queued but not started if MaxConcurrentRequests is 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:
BaseUrl comes from HttpModule on Global Settings. If the module is missing, URLs must be absolute (set useFullUrl = true or use FullUrl() on the builder).
- Request validation fails:
HttpRequestAsset.Validate(out errors) will return false if the URL is empty or malformed. Check the errors array for specifics.
Unity Editor