A clean, modern, JavaScript-style fetch wrapper for Unity using async/await and UnityWebRequest.
- Simple API:
UFetch.Get(),Post(),Put(),Delete() - Generic typed requests:
UFetch.Get<T>()for automatic JSON deserialization - JSON serialization via Newtonsoft.Json
- Multipart uploads with progress tracking
- Custom headers support
- Flexible error handling (exceptions or result objects)
- Fully awaitable and works in Unity runtime
UFetch requires Newtonsoft.Json. Install it first using one of these methods:
Option A: Unity's Official Package (Recommended)
- Open Package Manager (Window β Package Manager)
- Click + β Add package by name
- Enter:
com.unity.nuget.newtonsoft-json - Click Add
Option B: jillejr's Package
- Package Manager β + β Add package from git URL
- Enter:
https://github.com/jilleJr/Newtonsoft.Json-for-Unity.git#upm
Via Package Manager UI:
- Open Unity Package Manager (Window β Package Manager)
- Click the + button β Add package from git URL
- Enter:
https://github.com/herbou/UFetch.git?path=/Assets/UFetch - Click Add
Via manifest.json:
Add both packages to your Packages/manifest.json:
{
"dependencies": {
"com.unity.nuget.newtonsoft-json": "3.2.1",
"com.herbou.ufetch": "https://github.com/herbou/UFetch.git?path=/Assets/UFetch"
}
}using UnityEngine;
public class Example : MonoBehaviour {
async void Start() {
// Simple GET request
var response = await UFetch.Get("https://api.example.com/data");
Debug.Log(response.Text);
// Typed GET request
User user = await UFetch.Get<User>("https://api.example.com/user/123");
Debug.Log(user.name);
// POST with JSON
var jsonBody = JsonConvert.SerializeObject(new { score = 100 });
await UFetch.Post("https://api.example.com/submit", jsonBody);
// Download with progress
await UFetch.Get("https://example.com/file.zip", new UFetch.Options {
OnDownloadProgress = p => Debug.Log($"Progress: {p * 100}%")
});
}
}
public class User {
public string name;
public int age;
}Full documentation is available in the package:
- README.md - Quick start guide
- UFetch_Documentation.md - Complete API reference with examples
- Unity 2021.3 or later (for async/await support)
- Newtonsoft.Json for Unity (install manually - see Installation)
- .NET Standard 2.0+
| Method | Description |
|---|---|
Get(url, options) |
Performs a GET request |
Get<T>(url, options) |
GET request with typed JSON response |
Post(url, jsonBody, options) |
POST request with JSON body |
Post<T>(url, jsonBody, options) |
POST with typed response |
Put(url, jsonBody, options) |
PUT request with JSON body |
Delete(url, options) |
DELETE request |
Upload(url, formData, options) |
Multipart form upload |
new UFetch.Options {
Headers = new Dictionary<string, string> {
{ "Authorization", "Bearer TOKEN" }
},
OnDownloadProgress = progress => { /* 0.0 to 1.0 */ },
OnUploadProgress = progress => { /* 0.0 to 1.0 */ },
ThrowOnError = false // Disable exceptions for manual error handling
}UFetchResponse {
string Text; // Response as string
byte[] RawData; // Response as bytes
long StatusCode; // HTTP status code
bool IsError; // True if request failed
string Error; // Error message if failed
}// Authentication
var loginJson = JsonConvert.SerializeObject(new { email, password });
var token = await UFetch.Post<AuthToken>("https://api.com/login", loginJson);
// Authenticated request
var profile = await UFetch.Get<UserProfile>("https://api.com/profile",
new UFetch.Options {
Headers = { { "Authorization", $"Bearer {token.access_token}" } }
});var response = await UFetch.Get("https://example.com/image.png");
Texture2D texture = new Texture2D(2, 2);
texture.LoadImage(response.RawData);
myImage.texture = texture;byte[] fileData = File.ReadAllBytes("photo.jpg");
var form = new WWWForm();
form.AddField("title", "My Photo");
form.AddBinaryData("file", fileData, "photo.jpg", "image/jpeg");
await UFetch.Upload("https://api.com/upload", form, new UFetch.Options {
OnUploadProgress = p => uploadBar.value = p
});Assets/UFetch/ # UPM Package
βββ Runtime/ # Runtime code
β βββ UFetch.cs # Main implementation
β βββ UFetch.Runtime.asmdef
βββ Samples~/ # Optional samples (excluded from package)
β βββ Demo/
β βββ Demo.cs
βββ package.json # Package manifest
βββ README.md # Quick start
βββ LICENSE.md # MIT License
βββ UFetch_Documentation.md # Full docs
- Clone the repository
- Open the project in Unity 2021.3+
- The UFetch package is located in
Assets/UFetch/
MIT License - Free to use in personal and commercial projects.
See LICENSE.md for details.
Contributions, issues, and feature requests are welcome!
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- π Full Documentation
- π Issue Tracker
- π¬ Discussions
If you find UFetch helpful, please consider:
- Giving it a β on GitHub
- Sharing it with other Unity developers
- Contributing improvements or reporting issues
Made with β€οΈ for the Unity community