Skip to content

Sample usage

David Douglas edited this page Nov 7, 2017 · 2 revisions

Sample usage showing how to call "hello" Azure Function API:

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

	// Use this for initialization
	void Start () {
		StartCoroutine( SayHello(SayHelloCompleted) );
	}

	private IEnumerator SayHello(Action<IRestResponse<string>> callback = null) {
		RestRequest request = new RestRequest("https://***.azurewebsites.net/api/hello", Method.POST);
		request.AddHeader("Content-Type", "application/json");
		request.AddQueryParam("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);
	}

}
Clone this wiki locally