Accessing RESTful web apis from unity

Is it possible to get the WWW class to use any other http verb than GET or POST? I'm trying to access web apis wich relies on the correct the http verb for an operation.

Most of the time my apps will be running in the web player, so I guess I could create some javascript functions exposing the jquery $.ajax() or similar and call the javascript from unity, but that excludes debugging in the editor.

“The HTTP protocol only supports the GET and POST operations” ← not true

Silly me, I just realized I can use the `System.Net.HttpWebRequest`, it provides me with all the http-goodness I care for.

Even though this is an old question I wanted to chime in. There are a few solutions for using rest in Unity. They all involve libraries that re-implement http over sockets. Here’s one in particular:

It’s too bad that the built in Unity http api doesn’t support more verbs, and that the System.Net

classes aren’t functional in webplayer.

I’ve done for doing this below. Let’s go : ==>

using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System.Collections.Generic;
public class btnGetData : MonoBehaviour {
 void Start()
 {
     gameObject.GetComponent<Button>().onClick.AddListener(TaskOnClick);
 }
 IEnumerator WaitForWWW(WWW www)
 {
     yield return www;
    
     
     string txt = "";
     if (string.IsNullOrEmpty(www.error))
         txt = www.text;  //text of success
     else
         txt = www.error;  //error
     GameObject.Find("Txtdemo").GetComponent<Text>().text =  "++++++

" + txt;
}
void TaskOnClick()
{
try
{
GameObject.Find(“Txtdemo”).GetComponent().text = “starting…”;
string ourPostData = “{"plan":"TESTA02"”;
Dictionary<string,string> headers = new Dictionary<string, string>();
headers.Add(“Content-Type”, “application/json”);
//byte b = System.Text.Encoding.UTF8.GetBytes();
byte pData = System.Text.Encoding.ASCII.GetBytes(ourPostData.ToCharArray());
///POST by IIS hosting…
WWW api = new WWW(“http://192.168.1.120/si_aoi/api/total”, pData, headers);
///GET by IIS hosting…
///WWW api = new WWW(“http://192.168.1.120/si_aoi/api/total?dynamix={"plan":"TESTA02"”);
StartCoroutine(WaitForWWW(api));
}
catch (UnityException ex) { Debug.Log(ex.Message); }
}
}

Am I correct in thinking that KvanteTore can change his server to call something like an Update method on his application controller in response to a POST request as opposed to a PUT request?

But, that still wouldn’t work if youre trying to consume APIs that arent of your own.
Just throwing that out there.

Let me know what you’ve discovered since then.

There are existing tools for generating API clients for c# but they tend to be too generic and often use .NET HTTP client (which is not working on all platforms). I’ve been working on Unity friendly OpenAPI parser and assets generator GitHub - kolodi/UnityOpenApi: Unity friendly RESTful API client generator for some time, it resolves all issues with the multi-platform support and leverage many Unity-specific tools to provide an easiest possible way to work with the restful API. It’s not finished yet, so any contribution is welcomed.

Hi, there is in my github Working solution : Infinite-Contact-List-ScrollRect-Unity3D

The HTTP protocol only supports the GET and POST operations. REST is not part of HTTP, they're two completely different things. REST is just a specification for how the server acts and sends the data. If the data is over HTTP, you can get the REST data just like you would get the contents of a webpage (using GET). HTTP POST is only for posting forms or files back to the webserver. Any time you want to get anything off of a webserver, you use GET.

http://en.wikipedia.org/wiki/REST

http://en.wikipedia.org/wiki/HTTP

Reading both of those articles would probably be to your benefit.