Home

Awesome

REST Client for Unity

For Unity developers looking to use REST Services in their Unity game / app.

RESTClient for Unity is built on top of UnityWebRequest and Unity's JsonUtility to make it easier to compose REST requests and return the results serialized as native C# data model objects.

Features

How do I use this with cloud services?

Checkout the following projects for Unity which were built using this REST Client library as examples.

Example Usage

This snippet shows how to POST a REST request to a new Azure Function HTTP Trigger "hello" sample function:

using RESTClient;
using System;
public class RESTClientExample : MonoBehaviour {

  private string url = "https://***.azurewebsites.net/api/hello"; // Azure Function API endpoint
  private string code = "***"; // Azure Function code

	void Start () {
		StartCoroutine( SayHello(SayHelloCompleted) );
	}

	private IEnumerator SayHello(Action<IRestResponse<string>> callback = null) {
		RestRequest request = new RestRequest(url, Method.POST);
		request.AddHeader("Content-Type", "application/json");
		request.AddQueryParam("code", code);
		request.AddBody("{\"name\": \"unity\"}");
		yield return request.Request.Send();
		request.GetText(callback);
	}

	private void SayHelloCompleted(IRestResponse<string> response) {
		if (response.IsError) {
			Debug.LogError("Request error: " + response.StatusCode);
			return;
		}
		Debug.Log("Completed: " + response.Content);
	}

}

Requirements

Requires Unity v5.3 or greater as UnityWebRequest and JsonUtility features are used. Unity will be extending platform support for UnityWebRequest so keep Unity up to date if you need to support these additional platforms.

Supported platforms

Intended to work on all the platforms UnityWebRequest supports including:

Troubleshooting

Questions or tweet @deadlyfingers