Skip to content

unitycoder/OpenRest

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OpenRest - REST Client

A simple REST client for Unity3D with fluent interface. Unlike other clients, this client works both in the editor and in the build. and it requires EditorCoroutine package to work in the editor.

Table of Contents

Installation

The easiest way to install OpenRest is using UPM:

openupm add com.omid3098.openrest

Or install manually:

  • Install Newtonsoft.Json package from the Package Manager window -> Add package by name:
com.unity.nuget.newtonsoft-json
  • Install EditorCoroutine package from the Package Manager window

  • Copy Contents of the Packages folder into your project Packages/com.omid3098.openrest

Usage

Basic Usage

// Add required namespaces
using OpenRest;

// Create a rest client
var client =  RestClient.Get()
            .Url("https://jsonplaceholder.typicode.com/posts/1")
            .OnSuccess((response) => {
                Debug.Log(response);
            }).Send();

Complete Usage

        JObject jsonObject = new JObject(){
            {"title", "foo"},
            {"body", "bar"},
            {"userId", 1}
        };

        RestClient.Post()
            .Url("https://jsonplaceholder.typicode.com/posts/1")
            .Headers(new Dictionary<string, string> {
                { "Content-Type", "application/json" },
                { "Authorization", "Bearer " + API_KEY}
            }).JsonData(
                jsonObject.ToString(Formatting.None)
            ).OnSuccess((response) =>
            {
                Debug.Log(response);
            }).OnProgress((progress) =>
            {
                Debug.Log(progress);
            }).OnError((error) =>
            {
                Debug.Log(error);
            }).Send();

License

MIT

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%