npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

extensions.unity.network

v1.4.1

Published

Library for managering Network requests, especially REST API

Downloads

51

Readme

Unity Network REST

npm License Stand With Ukraine

REST plugin for client app/game to communicate with single or multiple remote servers using SOLID principles and clean code. Only JSON format is supported for data sending/receiving.

Features

  • :white_check_mark: Supported REST requests
    • ✔️ GET
    • ✔️ POST
    • ✔️ PUT
    • ✔️ DELETE
  • :white_check_mark: JSON serialization/deserialization
  • :white_check_mark: Headers control
  • :white_check_mark: Requests in dedicated background thread

How to install - Option 1 (RECOMMENDED)

  • Install ODIN Inspector
  • Install OpenUPM-CLI
  • Open command line in Unity project folder
  • openupm --registry https://registry.npmjs.org add extensions.unity.network

How to install - Option 2

{
  "dependencies": {
    "extensions.unity.network": "1.4.1",
  },
  "scopedRegistries": [
    {
      "name": "package.openupm.com",
      "url": "https://package.openupm.com",
      "scopes": [
        "extensions.unity",
        "com.cysharp",
        "com.neuecc"
      ]
    }
  ]
}

How to use

STEP 1: Create Server representation as ScriptableObject instance

Create class for representing server, let's call it RemoteServerSO. Extend the class from NetworkSO. In Unity Editor press right mouse click in project and create new instance of server representation using menu: Tools/Remote Server. Select the instance and put into server endpoint. We will use the instance for sending requests to the server.

[CreateAssetMenu(fileName = "RemoteServer", menuName = "Tools/Remote Server", order = 0)]
public class RemoteServerSO : NetworkSO
{

}

STEP 2: Create request

Let's imagine the server by the Enpoint api/data returns the JSON.

Each unique request in REST API should be represented as C# class. Let's create one GET request as example. Need to override Endpoint for this specific request.

public class GetDataRequest : RequestGet<Data>
{
    protected override string Endpoint => $"api/data";

    public GetDataRequest(RemoteServerSO remote) : base(remote) { }
}

Optional data processing

If needed to process received data from the request, need to override OnDataReceived

public class GetDataRequest : RequestGet<Data>
{
    protected override string Endpoint => $"api/data";

    public GetDataRequest(RemoteServerSO remote) : base(remote) { }
    
    protected override UniTask OnDataReceived(Data data)
    {
        // doing something with data
        return base.OnDataReceived(data);
    }
}

STEP 3: Send request

Creating request instance and providing server instance

var request = new GetRemoteConfigs(remoteServer);

Option 1 - just send request

request.SendRequest().Forget();

Option 2 - send request and wait for response with valid data deserialization

var data = (await request.SendRequest()).ResponseData;

Option 3 - send and subscribe on callback

request.SubscribeOnSuccess(data =>
{
    // doing something with data
}, this).SendRequest().Forget();

Request callbacks

Subscription should be done before call SendRequest()

// Response received, data successfully serialized from JSON to C# object
request.SubscribeOnSuccess(data =>
{
    // doing something with data
}, this);

// Response received, raw JSON data provided
request.SubscribeOnSuccessRaw(rawJson =>
{
    // doing something
}, this);

// Response received, JSON can't be deserialized for any reason
request.SubscribeOnSerializationError(rawJson =>
{
    // doing something
}, this);

// HTTP error
request.SubscribeOnHttpError(httpError =>
{
    // doing something
}, this);

// Network error, related with internet connection, can't reach the server at all
request.SubscribeOnNetworkError(networkError =>
{
    // doing something
}, this);

// Progress is float number in range from 0.0f to 1.0f
request.SubscribeOnProgress(progress =>
{
    // doing something with data
}, this);

// Request completed with boolean "success" status (true or false)
request.SubscribeOnComplete(success =>
{
    // doing something with data
}, this);