Giter Club home page Giter Club logo

cable's Introduction

Cable

Build status

Type-safe client-server communication for C# featuring Bridge.NET and NancyFx. It is a Remote Procedure Call (RPC) implementation for Bridge.NET as the client and Nancy as the Server.

Introducing Cable: Deep Dive Into Building Type-Safe Web Apps in C# with Bridge.NET and Nancy

Cable.ArticleSample Project used in the article to demonstrate Cable. The repo can be used a template for client/server apps. Everything is already set up.

Cable.StandaloneConverter Project that demonstrates using the Cable JSON converter stand-alone without HTTP abstractions

TL;DR

On the Nancy Server

Install Cable.Nancy from nuget

Install-Package Cable.Nancy

Define shared types interfaces in a seperate file SharedTypes.cs

public class Student
{
    public string Name { get; set; }
    public int Id { get; set; }
    public string[] Subjects { get; set; }
    public DateTime DateOfBirth { get; set; }
}

public interface IStudentService
{
    Task<IEnumerable<Student>> GetAllStudents();
    Task<Student> TryFindStudentByName(string name);
}

Register an implementation through a NancyModule:

public class StudentServiceModule : NancyModule
{
    public StudentServiceModule(IStudentService service)
    {
        // automatically generate routes for the provided implementation of IStudentService
        NancyServer.RegisterRoutesFor(this, service);
    }
}

On the Bridge.NET client

Install Cable.Bridge from nuget:

Install-Package Cable.Bridge

Reference the file SharedTypes.cs into your client project, making the types available.

Create a typed proxy and talk to server directly:

using System;
using Cable.Bridge;
using ServerSide;

namespace ClientSide
{
    public class Program
    {
        public static async void Main()
        {
            // resolve a typed proxy
            var studentService = BridgeClient.Resolve<IStudentService>();

            // call server just by calling the function
            var students = await studentService.GetAllStudents();

            // use the results directly
            foreach (var student in students)
            {
                var name = student.Name;
                var age = DateTime.Now.Year - student.DateOfBirth.Year;
                Console.WriteLine($"{name} is {age} years old");
            }
        }
    }
}

cable's People

Contributors

zaid-ajaj avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

zhaxg

cable's Issues

.Net Core compliance

Hi,

While Nancy and bridge.net have already supported .NET core, can we upgrade this repository to support it too?
However, having the support under different branch should be good , though.

What do you think?

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.