-
Notifications
You must be signed in to change notification settings - Fork 14
Web Requests Framework
We are using a custom generic structure for performing Web Requests in an asynchronous way. It's located in DCL.WebRequests assembly.
Currently, the exposed API looks like this:
public interface IWebRequestController
{
UniTask<GenericGetRequest> GetAsync(
CommonArguments commonArguments,
CancellationToken ct,
string reportCategory = ReportCategory.GENERIC_WEB_REQUEST,
WebRequestHeadersInfo? headersInfo = null,
WebRequestSignInfo? signInfo = null);
UniTask<GenericPostRequest> PostAsync(
CommonArguments commonArguments,
GenericPostArguments arguments,
CancellationToken ct,
string reportCategory = ReportCategory.GENERIC_WEB_REQUEST,
WebRequestHeadersInfo? headersInfo = null,
WebRequestSignInfo? signInfo = null);
UniTask<GetTextureWebRequest> GetTextureAsync(
CommonArguments commonArguments,
GetTextureArguments args,
CancellationToken ct,
string reportCategory = ReportCategory.GENERIC_WEB_REQUEST,
WebRequestHeadersInfo? headersInfo = null,
WebRequestSignInfo? signInfo = null);
}
Every type of request creates a strongly typed structure to define and restrain the set of possible operations. E.g. to prevent reading text from GetTexture request. This capability is not provided by Unity itself: it will just throw an exception.
The whole API is designed to provide an allocation-free way of setting parameters:
- Everything is designed with
Value Typesunless it's restricted by Unity API itself -
WebRequestHeadersInfouses the pool and is disposed of automatically when aWeb Requestfails or succeeds
public readonly URLAddress URL;
public readonly int AttemptsCount = 3;
public readonly int Timeout = 0;
Repetitions are handled inside the implementation of IWebRequestController. If needed (for test purposes) this behavior can be overridden.
To be implemented
Our scenarios of handling responses are common, therefore, several utilities are presented to unify the approaches and get rid of potential boiler-plate code.
- Generic
PostandGetrequestsOverwriteFromJson<T>CreateFromJson<T>GetDataCopy()- Calling these methods will provide data and automatically release the underlying request