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.
Sample main.cs (see demo/main.cs):
classApplication{publicstaticvoidMain(string[]args){if(args.Length==0){Usage();return;}varconfig=ParseAppConfig(args[0]);vartmpl=newEasyWeb.View.TemplateEngine.Razor();tmpl.LoadFromPath(config.HtmlTemplateBaseDir);varmemeStorage=newStorage.MemeFileStorage(config.MemeStorageBaseDir);varmemeTemplateStorage=newStorage.MemeTemplate();memeTemplateStorage.Load(config.MemeTemplateBaseDir);varhttpServer=newServer(newEasyWeb.Log.Console());varmemeCtrl=newController.MemeGen(tmpl,memeTemplateStorage,memeStorage,config.MemeWebPath);varassetsServer=newController.AssetsServer(config.AssetsBaseDir);httpServer.Handle("/assets/(?<file>.*)$",newStripPrefix("/assets/",assetsServer));httpServer.Handle("/",newHandlerFunc(memeCtrl.IndexPage));httpServer.Handle("/select-template",newHandlerFunc(memeCtrl.SelectTemplatePage));httpServer.Handle("/create-meme",newHandlerFunc(memeCtrl.CreateMemePage));httpServer.Handle("/save-meme",newHandlerFunc(memeCtrl.SaveMemePage));httpServer.NotFound(newController.NotFound());httpServer.ListenAndServe(config.BindAddress);}}Sample handler (see demo/handler.cs):
namespaceController{// [...]publicvoidIndexPage(IResponseWriterresponse,IRequestrequest,IUrlParamsurlParams){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:
namespaceController{// [...]publicclassNotFound:IHandler{publicvoidServeHttp(IResponseWriterresponse,IRequestrequest,IUrlParamsurlParams){response.WriteString("<html><body><h1>Website not found</h1></body></html>");}}// [...]}IHandler Interface (see EasyWeb/Net/Http/Handler.cs):
publicinterfaceIHandler{voidServeHttp(IResponseWriterresponse,IRequestrequest,IUrlParamsurlParams);}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.
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.
- Better test coverage
DELETE,GET,HEAD,OPTIONS,POST,PUTandPATCHrequest helpers- Better exception handling
- Documentation
- More features in general
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) :-)