Coder Social home page Coder Social logo

duovia-http's Introduction

duovia-http

DuoVia.Http

An OWIN-based Lightweight Services Library for .NET.

Exciting News

DuoVia.Http.Host is now an OWIN middleware component rather than a stand alone app. This makes it easy to use DuoVia.Http side-by-side with other OWIN frameworks and applications. Special thanks to Chris Ross for making the recommendation.

Based on the feature set of DuoVia.Net but with a focus on using HTTP via OWIN with JSON rather than binary serialization. Initial testing shows that this library keeps pace with the binary serialization. This is in large part due to the use the ultra-fast ServiceStack.Text serializer.

There are two NuGet libraries that you will need. The client proxy library DuoVia.Http and the OWIN hosting library DuoVia.Http.Host.

The host exposes a raw "metadata" endpoint that defines the services being hosted, their operations and their parameters in JSON. In the future we want to add a nice HTML response when the Accept header is not application/json.

While not recommended, this allows you to build your own client or access your service with a non-.NET client.

And one very cool thing you probably won't find in any other RPC-style library is support for method overloads and out and ref parameters.

Using the library is easy. Write your interface and DTO's into one assembly and your implementation into another assembly. This allows you to avoid distributing your implementation to clients.

Now just hook up the host and the client as shown below. Check out the integration projects. Also note that you will need the OWIN self host NuGet package to create a similar console app that hosts your service.

First, your code that hosts your service.

    // must have this reference to provide Host extension method
    using DuoVia.Http.Host;
    // other using and namespace declarations removed for brevity

    class Program
    {
        static void Main(string[] args)
        {
            string baseUrl = "http://localhost:12345/";
            var options = new StartOptions(baseUrl);
            using (WebApp.Start<Startup>(options))
            {
                // Keep the server going until we're done
                Console.WriteLine("Press Any Key To Exit");
                Console.ReadKey();
            }
        }
    }

    // your startup class for application initialization
    internal class Startup
    {
        // Invoked once at startup to configure your application.
        public void Configuration(IAppBuilder app)
        {
            // create the service implementation
            IMyTest test = new MyTest();

            // use the middelware extension to host it
            app.Host<IMyTest>(test);

            // NOTE: host as many services as you want
            // but host only one instance of an interface
        }
    }

Second, your code that accesses your service (the client). What could be easier.

    static void Main(string[] args)
    {
        var url = "http://localhost:12345";
        var client = HttpClient.Create<IMyTest>(url);

        // now call methods on the interface as if it were local
        var name = client.GetName("heyhey");
        var thing = client.DoSomething("today");

        Console.WriteLine("{0} {1}", name, thing);

        Console.WriteLine("Press Any Key To Exit");
        Console.ReadKey();
    }

duovia-http's People

Contributors

tylerje avatar

Watchers

James Cloos avatar  avatar

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.