Git Product home page Git Product logo

network.js's Introduction

network.js

This is a simple Ajax and SignalR networking wrapper that simplifies server-client communication in lightweight web applications.

Note: This library requires ASP.NET Core SignalR. Without SignalR, only network.post and network.get will work.

Importing

CDN

In your .html file, add this to your <head> tag

<!-- Required Dependencies --->
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<!-- Optional Dependencies --->
<script src="https://cdnjs.cloudflare.com/ajax/libs/aspnet-signalr/1.1.4/signalr.min.js"></script>
<!-- notify.js --->
<script src="https://cdn.mistad.net/network.js"></script>

Usage

SignalR

Initialize a connection to your hub: network.init([hub path string])

network.init('/route/to/hub/');

Register any expected events: network.on([event], [action callback)

network.on('eventName', obj => {
    var result = JSON.stringify(obj);
    console.log(result);
});

Start the connection to your hub: network.connect([action callback])

network.connect(err => {
    if (err) console.error(err);
});

Invoke the event on your server's hub: network.send([event], [json object], [error callback])

network.send('eventName', obj, err => {
    console.error(err);
});

Ajax (POST/GET)

Submit a POST request: network.post([path], [payload], [action callback])

network.post('/route/to/method', obj, response => {
    var result = JSON.stringify(response);
    console.log(result);
});

Submit a GET request: network.get([path], [optional payload], [action callback])

network.get('/route/to/method', obj, response => {
    var result = JSON.stringify(response);
    console.log(result);
});

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.