Coder Social home page Coder Social logo

dragonquest / easy-web Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 3.19 MB

EasyWeb is a lightweight and simple framework for building HTTP based applications on the .NET Framework and Mono.

License: MIT License

C# 96.62% Makefile 2.66% CSS 0.72%
mono c-sharp web easyweb http framework open-source mit easy-web lightweight-http

easy-web's Introduction

EasyWeb - Lightweight HTTP Framework

EasyWeb is a lightweight and simple framework for building HTTP based applications on the .NET Framework and Mono.

The goal was to remove all the fat the other frameworks provide by implementing highly reusable and small modular components. This allows to quickly add/provide a simple Web GUI for new or existing C# applications.

The interface and structure is inspired by Go's net/http package.

Write Your Application

Sample main.cs (see demo/main.cs):

class Application
{
    public static void Main(string[] args)
    {
        if(args.Length == 0)
        {
            Usage();
            return;
        }
        var config = ParseAppConfig(args[0]);

        var tmpl = new EasyWeb.View.TemplateEngine.Razor();
        tmpl.LoadFromPath(config.HtmlTemplateBaseDir);

        var memeStorage = new Storage.MemeFileStorage(config.MemeStorageBaseDir);

        var memeTemplateStorage = new Storage.MemeTemplate();
        memeTemplateStorage.Load(config.MemeTemplateBaseDir);

        var httpServer = new Server(new EasyWeb.Log.Console());

        var memeCtrl = new Controller.MemeGen(tmpl, memeTemplateStorage, memeStorage, config.MemeWebPath);
        var assetsServer = new Controller.AssetsServer(config.AssetsBaseDir);

        httpServer.Handle("/assets/(?<file>.*)$", new StripPrefix("/assets/", assetsServer));
        httpServer.Handle("/", new HandlerFunc(memeCtrl.IndexPage));
        httpServer.Handle("/select-template", new HandlerFunc(memeCtrl.SelectTemplatePage));
        httpServer.Handle("/create-meme", new HandlerFunc(memeCtrl.CreateMemePage));
        httpServer.Handle("/save-meme", new HandlerFunc(memeCtrl.SaveMemePage));
        httpServer.NotFound(new Controller.NotFound());

        httpServer.ListenAndServe(config.BindAddress);
    }
}

Sample handler (see demo/handler.cs):

namespace Controller 
{
	// [...]
	public void IndexPage(IResponseWriter response, IRequest request, IUrlParams urlParams)
	{
		response.WriteString(_template.Render("index.cshtml", new
        {
            PublicPath = _memeWebPath,
            Memes = Enumerable.Reverse(_meme.ListAll())
        }));
	}
	// [...]
}

Sample NotFound handler (see demo/handler.cs):

The NotFound Handler is a simple IHandler and therefore easily extendable. Example:

namespace Controller 
{
	// [...]
	public class NotFound : IHandler
	{
		public void ServeHttp(IResponseWriter response, IRequest request, IUrlParams urlParams)
		{
			response.WriteString("<html><body><h1>Website not found</h1></body></html>");
		}
	}
	// [...]
}

IHandler Interface (see EasyWeb/Net/Http/Handler.cs):

    public interface IHandler
    {
        void ServeHttp(IResponseWriter response, IRequest request, IUrlParams urlParams);
    }

Meme Generator Demo Application

The repository contains a demo application for creating and storing memes incl. some templates. Please check out the directory demo/ and run make to compile it and then run the demo app by make run.

Motivation, Author & License

I, Andreas Näpflin, created EasyWeb in order to learn more about the C# programming language. Although it's simple and lightweight it has not been used in production yet so I would highly recommend to use a battle-tested framework instead. For example Nancy.

The project is licensed under the MIT license. Please check out the LICENSE file.

TODO

  • Better test coverage
  • DELETE, GET, HEAD, OPTIONS, POST, PUT and PATCH request helpers
  • Better exception handling
  • Documentation
  • More features in general

Development status

I won't continue to develop this application because it was a "Learning project" only. If you find it interesting and would like to see more features or that I should continue to work on it then please create an issue (and I might consider to code for it again) :-)

easy-web's People

Watchers

 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.