/// <summary> /// Put record if not exists for idempotency /// </summary> /// <returns></returns> private static IEnumerator PrepareForDelete() { var yieldInstruction = ObservableUnityWebRequest .HeadAsObservable("http://localhost:3001/fruits/3") .ToYieldInstruction(false); yield return(yieldInstruction); if (yieldInstruction.HasError && yieldInstruction.Error is UnityWebRequestErrorException.NotFound) { yield return(ObservableUnityWebRequest .PostAsObservable("http://localhost:3001/fruits", Encoding.UTF8.GetBytes("id=3&name=Grape&name_ja=ぶどう")) .ToYieldInstruction(false)); } }
public IEnumerator HttpPostAsObservable() { yield return(PrepareForPost()); var yieldInstruction = ObservableUnityWebRequest .PostAsObservable("http://localhost:3001/fruits", "id=4&name=Banana&name_ja=ばなな") .ToYieldInstruction(false); yield return(yieldInstruction); var fruit = JsonUtility.FromJson <Fruit>(yieldInstruction.Result); Assert.AreEqual(4, fruit.Id); Assert.AreEqual("Banana", fruit.Name); Assert.AreEqual("ばなな", fruit.NameJapanese); }