GithubHelp home page GithubHelp logo

anna-rx / anna Goto Github PK

View Code? Open in Web Editor NEW
140.0 15.0 23.0 759 KB

Event-driven http server library with ReactiveExtensions inspired in node.js and nancy

License: MIT License

C# 65.24% XSLT 34.46% Shell 0.30%

anna's Introduction

Anna Build status NuGet NuGet downloads

Anna is an event-driven HTTP server library built with ReactiveExtensions (Rx). Anna was inspired in Node.js and Nancy.

Anna exposes observable sequences of HTTP requests to which you can subscribe to handle the request.

using (var server = new HttpServer("http://*:1234/"))
{
    // simple basic usage, all subscriptions will run in a single event-loop
    server.GET("/hello/{Name}")
          .Subscribe(ctx => ctx.Respond("Hello, " + ctx.Request.UriArguments.Name + "!"));

    // use Rx LINQ operators
    server.POST("/hi/{Name}")
          .Where(ctx => ctx.Request.UriArguments.Name == "George")
          .Subscribe(ctx => ctx.Respond("Hi, George!"));

    server.POST("/hi/{Name}")
          .Where(ctx => ctx.Request.UriArguments.Name == "Pete")
          .Subscribe(ctx => ctx.Respond("Hi, Pete!"));
}

Another example is in my blog: Long polling chat with Anna

License

The MIT License (MIT)

Copyright (c) 2011, 2012, 2013, 2014 José F. Romaniello

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

anna's People

Contributors

almostwaldo avatar dmalikov avatar eteeselink avatar jfromaniello avatar virus-x avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

anna's Issues

Roadmap

Hey guys-

I am curious what you guys' thoughts are on the future of Anna? It seems like it would make for a great base for a Microservice framework (haven't seen many in the .NET world). I'm debating on whether I should fork and create my own based on Anna or contribute here... let me know what you think.

Exceptions which fire within Response.Send() cause entire app to exit

e.g. changing the code to this:

WriteStream(listenerResponse.OutputStream)
.Subscribe(s =>
{
    try
    {
        s.Close();

        throw new System.Net.Sockets.SocketException();

will cause the entire app to exit. Would be nice to pass any exceptions back up the chain for handling via the app itself.

Anna and the OWIN specifiication

In the verge of the recent move in the project, a friend of mine mentioned if Anna could potentially be turned into an OWIN middleware. Considering the grim future of System.Web from which Anna currently depends on, I think this could be a good move in the near future.

I know that NancyFx can act as an OWIN middleware, but they do not rely on Rx like Anna. I do not have enough knowledge of Katana or the OWIN specification to say how the Rx pipeline would fit inside a middleware without breaking the chain and how Rx scheduling would come into play.

Any ideas on how this could be accomplished?

Url with * (wildcard)

If I try and use a path like "/wildcarded-*/" I get the exception:

System.FormatException : The UriTemplate '/wildcarded-*' is not valid; the wildcard ('*') cannot           appear in a variable name or literal, unless as a construct for a wildcard segment. Note that a wildcard  segment, either a literal or a variable, is valid only as the last path segment in the template; the     wildcard can appear only once. See the documentation for UriTemplate for more details.

   at System.UriTemplateLiteralPathSegment.CreateFromUriTemplate(String segment, UriTemplate template)
   at System.UriTemplatePathSegment.CreateFromUriTemplate(String segment, UriTemplate template)
   at System.UriTemplate..ctor(String template, Boolean ignoreTrailingSlash, IDictionary\`2 additionalDefaults)
   at System.UriTemplate..ctor(String template)
   at Anna.HttpServer.OnUriAndMethod(String uri, String method)

I can't see a way of escaping the '*' in the UrlTemplate documentation. Does anybody know how to do it?

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.