GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - Unity3dAzure/RESTClient: REST Client for Unity with JSON and XML parsing. (Features JSON helper to handle nested arrays and deserializing abstract types)

BranchesTags
Open more actions menu

Latest commit

 

History

15 Commits
15 Commits

Folders and files

NameName
Last commit message
Last commit date
helpers
helpers
 
 
http
http
 
 
model
model
 
 
.gitignore
.gitignore
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
RestClient.cs
RestClient.cs
 
 

Repository files navigation

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

  • Methods to add request body, headers and query strings to REST requests.
  • Ability to return result as native object or as plain text.
  • Work around for nested arrays.
  • Work around for parsing abstract types on UWP.

How do I use this with cloud services?

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

  • Azure App Services
  • Azure Blob Storage
  • Azure Functions
  • Nether (serverless)

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:

  • Unity Editor (Mac/PC) and Standalone players
  • iOS
  • Android
  • Windows 10 (UWP)

Troubleshooting

  • Remember to wrap async calls with StartCoroutine()
  • Before building for a target platform remember to check the Internet Client capability is enabled in the Unity player settings, otherwise all REST calls will fail with a '-1' status error.

Questions or tweet @deadlyfingers

About

REST Client for Unity with JSON and XML parsing. (Features JSON helper to handle nested arrays and deserializing abstract types)

deadlyfingers.net

Topics

json-parsingjsonutilityrestclientunityunitywebrequestxml-parsing

Resources

Readme
MIT license
Activity
Custom properties

Stars

53 stars

Watchers

4 watching

Forks

14 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.