The AccelByte SDK is a specialized set of libraries and examples that seamlessly integrate with AccelByte backend services. This service gives you a convenience way to wrap web requests in function calls, so that you will be able to save more time to focus on your game while the service is working for you in the backstage. In doing so, the AccelByte SDK provides you with these key features:
- Custom Coroutine System Under the Hood.
- Easy to Use API.
- Automatically Retry Temporary Server Errors.
- Access Token Management
Custom Coroutine System Under the Hood
AccelByte SDK is compatible with Unity 2017 or newer. Due to Unity 2017 still lags behind state of the art .NET technology, we make our own coroutine system inspired by Unity. Having our own coroutine system has some advantages:
* It enables us to have it run on separate thread from main thread * It can leverage more mature HttpWebRequest from .NET framework, instead of UnityWebRequest * It can return value, unlike Unity coroutine that doesn't really care about returning a value * It can have multiple HTTP requests running with only a single worker thread
We use this custom coroutine system under the hood, so most of the time user don't need to care about it. Any HTTP call will be mostly executed in background thread, except a little bit at the end of its execution. Unity doesn't support manipulating Unity objects from other thread. So, for convenience, we have our own coroutine runner just to give back objects from HTTP call to the main thread.
Easy to Use API
AccelByte SDK APIs uses continuation passing style for calling HTTP REST API, which pass a callback that can be used to return the value from a HTTP response. Typically, an HTTP call is abstracted as
public void CallHttpRestApi(TReqParam1 param1, TReqParam2 param2, ResultCallback<TResponse> callback)
ResultCallback<T> is a delegate that accepts Result<T> as its parameter, while ResultCallback accepts Result. We use Result<T> type because we want to avoid exception in our code base, so we combine error code and returned value. The class Result<T> is generic class of T and have 3 properties:
- Result<T>.IsError indicates that the result of a request is normal or has an error.
- Result<T>.Error have error code and error message
- Result<T>.Value have the type of T and only meaningful if Result<T>.IsError is false.
Because of this, making HTTP requests is as easy as calling a method.
Automatically Retry Temporary Server Errors
Temporary server errors (HTTP status 5xx) will be automatically retried if it failed, with exponential backoff and some randomization.
Access Token Management
AccelByte SDK will automatically handle user access tokens expiry, by calling refresh token to get new access token at about 70% - 90% near expiration time (randomly spread).