UniRetrofit is a lightweight wrapper around Proyecto26/RestClient, inspired by Retrofit (Android).
It simplifies working with HTTP requests in Unity, adds support for interceptors, authorization, and convenient integration with Promises (RSG) and Reactive Extensions (R3).
Assets/
└── Scripts/
└── UniRetrofit/
├── RestClientWrapper.cs // Promise-based version (RSG.Promise)
└── RestClientRxWrapper.cs // Observable-based version (R3.Observable)
- ✨ Retrofit-like interface
- 🔄 Support for interceptors (
IRestInterceptor)OnRequest— modify the request before sendingOnResponse— handle the responseOnError— handle errors
- 🔑 Authorization support via
IAuthHandler- automatic token refresh on
401 Unauthorized
- automatic token refresh on
- ⚡ Two implementations:
RestClientWrapper— based onRSG.PromiseRestClientRxWrapper— based onR3.Observable
- Download and install Proyecto26 RestClient.
- Install RSG Promises.
- If you need Rx-style, install R3 (Reactive Extensions for Unity).
Place UniRetrofit in your project:
Assets/Scripts/UniRetrofit
using Proyecto26;
using UnityEngine;
public class Example : MonoBehaviour
{
private RestClientWrapper client;
void Start()
{
client = new RestClientWrapper();
var request = new RequestHelper
{
Uri = "https://jsonplaceholder.typicode.com/posts/1"
};
client.Get<Post>(request).Then(post =>
{
Debug.Log($"Title: {post.title}");
}).Catch(err =>
{
Debug.LogError(err);
});
}
}
public class Post
{
public int userId;
public int id;
public string title;
public string body;
}Rx version (Observable)
using Proyecto26;
using R3;
using UnityEngine;
public class ExampleRx : MonoBehaviour
{
private RestClientRxWrapper client;
void Start()
{
client = new RestClientRxWrapper();
var request = new RequestHelper
{
Uri = "https://jsonplaceholder.typicode.com/posts/1"
};
client.Get<Post>(request)
.Subscribe(
post => Debug.Log($"Rx Title: {post.title}"),
error => Debug.LogError(error),
() => Debug.Log("Completed"));
}
}🔒 Authorization
You can implement IAuthHandler to automatically refresh tokens when a 401 Unauthorized error occurs.
public interface IAuthHandler
{
bool CanHandle(Exception error);
IPromise<bool> TryRefreshToken();
RequestHelper CloneRequest(RequestHelper original);
}🧩 Interceptors
Interceptors allow you to add headers, log requests, and handle responses.
public class LoggingInterceptor : IRestInterceptor
{
public void OnRequest(ref RequestHelper request)
{
Debug.Log($"➡️ Request: {request.Uri}");
}
public void OnResponse(RequestHelper request, ResponseHelper response)
{
Debug.Log($"⬅️ Response: {response.StatusCode}");
}
public void OnError(RequestHelper request, Exception exception)
{
Debug.LogError($"❌ Error: {exception.Message}");
}
}📌 TODO (roadmap)
- DSL with annotations ([Get], [Post], [Body])
- API interface generation like Retrofit
- Response caching
- Unity Addressables support for asset loading