UnityRestClient 一个Unity3d开发人员的Restful 客户端

一个Restful Client,允许在Unity3d中进行简单的GET,POST,PUT和DELETE http调用。

.NET 其它杂项

访问GitHub主页

共48Star

详细介绍

UnityRestClient

A Restful Client that allows making simple GET, POST, PUT, and DELETE http calls from within Unity3d.

How to Use It ?

There are two scenes currently in the project that can be used to find out how to use it. Also few snippets below to demo its functionality within Unity3d.

  1. Example of how to call Azure Vision API
// setup the request header
RequestHeader clientHeader = new RequestHeader {
    Key = clientId,
    Value = clientSecret
};

// build image url required by Azure Vision OCR
ImageUrl imageUrl = new ImageUrl {
    Url = "https://github.com/dilmerv/AzureVisionAPI/blob/master/images/IMG_5301.JPG?raw=true"
};

// send a post request
StartCoroutine(RestWebClient.Instance.HttpPost(baseUrl, JsonUtility.ToJson(imageUrl), (r) => OnRequestComplete(r), new List<RequestHeader> 
{
    clientHeader
}));
  1. Example of Get and Post
// send a get request
StartCoroutine(RestWebClient.Instance.HttpGet($"{baseUrl}api/values", (r) => OnRequestComplete(r)));

// setup the request header
RequestHeader header = new RequestHeader {
    Key = "Content-Type",
    Value = "application/json"
};

// send a post request
StartCoroutine(RestWebClient.Instance.HttpPost($"{baseUrl}api/values", 
JsonUtility.ToJson(new Player { FullName = "John Doe" }), 
    (r) => OnRequestComplete(r), new List<RequestHeader> { header } ));