WebRequest

A robust HTTP client solution for Unity, offering flexible API management, automatic retries, and comprehensive request handling using .NET's HttpClient.

In One Line

REST assured, your requests are in good hands!

Overview

AceLand WebRequest is a modern web request solution designed specifically for Unity projects, providing a fluent interface for API calls with built-in error handling, retry mechanisms, and API section management. It uses .NET's HttpClient instead of UnityWebRequest for better performance and more control.

Package Info

display name

AceLand WebRequest

package name

latest version

2.2.3

namespace

dependencies


Why Use It?

  • Modern Architecture: Built on .NET's HttpClient for better performance and reliability

  • Flexible API Management: Test and switch between different API configurations in editor

  • Built-in Retry Logic: Automatic retry mechanism with configurable intervals

  • Type-Safe Builder Pattern: Fluent interface for building requests with compile-time safety

  • Comprehensive Error Handling: Detailed error logging and exception management

  • Multiple Content Types: Support for JSON, Form, and Multipart request types


Key Features

  • Custom retry intervals and timeout settings

  • Comprehensive logging system with different build levels

  • HTTPS enforcement option

  • Automatic timestamp header injection

  • JSON validation before sending

  • Support for cancellation tokens

  • Editor tools for API section management


Project Settings

Logging

---

Logging Level

Level of Logging on web request default: BuildLevel.Production

Result Logging Level

Level of Logging on request success

default: BuildLevel.DevelopmentBuild

Full Logging Level

Level of Logging on all request logs content.

Logs will contain all parameters, headers and body contents. default: BuildLevel.DevelopmentBuild

Checking Options

---

Check Json Before Send

Check given content is a valid json before send request. This may be expensive if big content. Default: false

Force Https Scheme

Require request url is https if true. Otherwise http will also ok. Default: true

Request Options

---

Request Timeout

Default timeout if not set in request handle. Default: 3000 ms

Long Request Timeout

Default long request timeout. It will be set if building request handle with long request. Default: 15000 ms

Request Retry

How many times will retry on connection error including timeout. Default: 3

Retry Interval

Interval between each retry. Default: [ 400, 800, 1600, 3200, 6400, 12800, 25600] in ms

Header Auto Fill

---

Add Time In Header

Add send time in header automatically. Default: true

Time Key

key of Time in header. default: Time

Auto Fill Headers

Add default headers on each Request. Same headers will be covered by WithHeaders options on building Request. Default: { "User-Agent", "Mozilla/5.0" }

API Sections Profiles

---

Api Sections (c)

This is a list of API Sections Profiles. title bar: + add new field - delete last field

in line: - delete field * apply to Current API Section

Default API Section

---

Section Name

[Lock] default API section.

Api Url

[Lock] API URL of default section.


API


API Section

API section is a profile built with scriptable object.

  1. Create a project and set the values, then set in Project Settings.

API Sections Profile
  1. In Project Settings, find API Sections Profiles section, and press + to add a new row. Add more sections as your needs.

API Sections Profiles
  1. Press * to set default. the default section will show in the below section.

Default API Section

Basic Usage

Building request is easy.

  • start with request method

  • chain with url first

  • add parameters if necessary

  • add Header if necessary, see Project Settings

  • add Body if necessary, see Request Body


Request Body

In real-world experience, servers, proxies or clients will ignore body on methods even allowed by spec.

For a promise of communictaion, our request handle will follow the modern experience.

Method
Json Body
Multipart Body
Form Body

Get

Post

Put

Patch

Delete


Exception Handling

IRequestHandle will throw serval exception types on catching errors.

Exception Type
Description
Retry

FileNotFoundException

  • file not exists in multipart body

InvalidDataException

  • invalide data in multipart body

WebException

  • connection error

HttpServerErrorException

  • ≥ 500 all server errors

  • 429 too many requests

HttpErrorException

  • other http errors out of HttpServerErrorException

HttpRequestException

  • unexpected http errors

JsonReaderException

  • unknown response content

OperationCanceledException

  • request canceled by user

  • request canceled by unknown reason

Exception

  • retry on other exception

  • throw on reaching retry limit

other known exceptions

  • develop level errors

other unknown exceptions

  • unexpected task cancelation


Sample of Weather Widget

For example, there is a Weather Widget on canvas. It will refresh every set time.

Work with Promise Awaiter for thread-safe and clear coding structure.

Please read Task Utils for details.


Advanced Sample

This is a sample of building a User Authorization API serivce and how to use it. An API section profile is already set in project settings and set as default.

Following library and packages are using in above example:

Last updated