| name | web-requests |
| description | Web request framework for HTTP operations. Use when making API calls, HTTP/REST requests, fetching data from server, downloading content via IWebRequestController, parsing responses, building URLs with URLBuilder, signing requests with Web3 auth chains, or configuring retry policies. |
| user-invocable | false |
Web Requests
Sources
docs/web-requests-framework.md — Custom web request framework
docs/web3-authentication.md — Web3 authentication, identity, and signing
IWebRequestController API
The primary interface for all HTTP operations:
var response = await webRequestController.GetAsync(commonArguments, ct, ReportCategory.AUTHENTICATION);
var response = await webRequestController.PostAsync(commonArguments, body, ct, ReportCategory.MY_CATEGORY);
var response = await webRequestController.GetTextureAsync(commonArguments, ct, ReportCategory.TEXTURES);
CommonArguments
var commonArguments = new CommonArguments(
url,
attemptsCount: 3,
timeout: 0
);
Response Parsing
Use GenericDownloadHandlerUtils for response deserialization:
await response.OverwriteFromJson(existingObject);
MyDto dto = await response.CreateFromJson<MyDto>();
MyDto dto = await response.CreateFromNewtonsoftJsonAsync<MyDto>();
byte[] data = await response.GetDataCopy();
Code Example — URL Building + Request + Deserialization
From TokenFileAuthenticator.cs:
private async UniTask<IWeb3Identity> LoginAsync(CancellationToken ct)
{
string token = contentResult.Value;
urlBuilder.Clear();
urlBuilder.AppendDomain(URLDomain.FromString(authApiUrl))
.AppendPath(new URLPath($"identities/{token}"));
var commonArguments = new CommonArguments(urlBuilder.Build());
IdentityAuthResponseDto json = await webRequestController
.GetAsync(commonArguments, ct, ReportCategory.AUTHENTICATION)
.CreateFromNewtonsoftJsonAsync<IdentityAuthResponseDto>();
var authChain = AuthChain.Create();
foreach (AuthLink authLink in json.identity.authChain)
authChain.Set(authLink);
}
Request Signing
For authenticated requests, use WebRequestSignInfo:
var signInfo = new WebRequestSignInfo(signUrl);
var response = await webRequestController.GetAsync(commonArguments, ct, reportCategory, signInfo);
Auth Chain Construction
AuthChain authChain = identity.Sign("payload");
int i = 0;
foreach (AuthLink link in authChain)
{
request.SetRequestHeader($"x-identity-auth-chain-{i}", link.ToJson());
i++;
}
Identity Access
string address = web3IdentityCache.Identity.Address;
if (web3IdentityCache.Identity != null) { }
Retry Policy
Default Behavior
- Only GET requests are idempotent by default
- Signed requests are NOT idempotent (won't retry)
- Default: up to 2 retries with exponential backoff (1s base, 3x multiplier)
Error Code Qualification
| Code | Retry? | Reason |
|---|
| 400 | No | Bad Request |
| 401 | No | Unauthorized |
| 403 | No | Forbidden |
| 404 | No | Not Found |
| 408 | Yes | Request Timeout |
| 429 | Yes | Too Many Requests |
| 500 | Yes | Internal Server Error |
| 502 | Yes | Bad Gateway |
| 503 | Yes | Service Unavailable |
| 504 | Yes | Gateway Timeout |
| 511 | No | Network Auth Required |
Forcing Retries
RetryPolicy.Enforce()
JS API
No retries unless Retry-Delay header present on 429/503.
URL Utilities
Use typed URL structures from URLHelpers:
var domain = URLDomain.FromString("https://api.example.com");
var address = URLAddress.FromString("https://api.example.com/v1/users");
var builder = new URLBuilder();
builder.Clear();
builder.AppendDomain(domain)
.AppendPath(new URLPath("v1/users"))
.AppendParameter(new URLParameter("page", "1"));
URLAddress url = builder.Build();
Design Notes
- The framework is designed to be allocation-free — value types throughout
- Why: HTTP requests happen frequently in hot paths; GC pressure from request objects would cause frame hitches in the Unity game loop.
WebRequestHeadersInfo uses pooling for header storage
IWebRequestsAnalyticsContainer tracks ongoing requests for analytics
- Signed requests are not retried by default
- Why: Auth chains are time-sensitive — replaying a signed request after delay would fail validation, so retrying is wasteful and potentially confusing for error handling.