Giter Club home page Giter Club logo

i4004 / simplify.web Goto Github PK

View Code? Open in Web Editor NEW
23.0 3.0 8.0 9.13 MB

Moved to https://github.com/SimplifyNet. Simplify.Web is a lightweight and fast server-side .NET web-framework based on MVC and OWIN for building HTTP based web-applications, RESTful APIs etc.

Home Page: https://web.simplifynet.dev

License: GNU Lesser General Public License v3.0

C# 64.11% Smarty 0.89% HTML 1.70% CSS 0.86% JavaScript 30.86% TypeScript 1.50% Vue 0.08%
owin mvc dot-net web-framework web-application-framework c-sharp mvvm fast simplify mono-support

simplify.web's Introduction

Simplify.Web

Simplify

Simplify.Web is a lightweight and fast server-side .NET web-framework based on MVC and OWIN patterns for building HTTP based web-applications, RESTful APIs etc.

It can be used as:

  • An API backend framework
  • As a mix of API backend + some SPA front end like Angular
  • As an old way backend generated web-site

It can be hosted:

  • The same way as an ApsNetCore MVC application (On IIS, or as a console application)
  • Inside a windows service

This project is a continuator of AcspNet web-framework

Package status

Latest version Nuget version
Dependencies Libraries.io dependency status for latest release

Issues

Issues board

Build status

Branch Status
master AppVeyor Build status
develop AppVeyor Build status

Main features

  • Comes as Microsoft.AspNetCore OWIN middleware
  • Can be used as an API backend only with front-end frameworks
  • Based on MVC and MVVM patterns
  • Lightweight & Fast
  • Uses switchable IOC container for itself and controllers, views constructor injection (Simplify.DI)
  • Support async controllers
  • Supports controllers which can be run on any request
  • Localization-friendly (supports templates, strings and data files localization by default)
  • Uses fast templates engine (Simplify.Templates)
  • Mocking-friendly
  • Mono-friendly

Quick start

There is a templates package available at nuget.org for Simplify.Web. It contains a couple of templates which can be a good starting point for your application.

Installing a templates package:

dotnet new -i Simplify.Web.Templates
Template Short Name
Angular template sweb.angular
Api template sweb.api
Minimal template sweb.minimal
Windows service hosted api template sweb.api.windowsservice

Use the short name to create a project based on selected template:

dotnet new sweb.angular -n HelloWorldApplication

Then just run project via F5 (it will download all required nuget and npm packages at first build).

API outgoing JSON controller example

[Get("api/v1/weatherTypes")]
public class SampleDataController : Controller
{
    private static readonly string[] Summaries =
    {
        "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
    };

    public override ControllerResponse Invoke()
    {
        try
        {
            return new Json(items);
        }
        catch (Exception e)
        {
            Console.WriteLine(e);

            return StatusCode(500);
        }
    }
}

API ingoing JSON controller example

[Post("api/v1/sendMessage")]
public class SampleDataController : Controller<SampleModel>
{
    public override ControllerResponse Invoke()
    {
        try
        {
            Trace.WriteLine($"Object with message received: {Model.Message}");

            return NoContent();
        }
        catch (Exception e) when (e is ModelValidationException || e is Newtonsoft.Json.JsonException)
        {
            return StatusCode(400, e.Message);
        }
        catch (Exception e)
        {
            Console.WriteLine(e);

            return StatusCode(500, "Site error!");
        }
    }
}

public class SampleModel
{
    [Required]
    public string Message { get; set; }
}

Some simple HTML generation controllers example

Static page controller

// Controller will be executed only on HTTP GET request like http://mysite.com/about
[Get("about")]
public class AboutController : Controller
{
    public override ControllerResponse Invoke()
    {
        // About.tpl content will be inserted into {MainContent} in Master.tpl
        return new StaticTpl("Static/About", StringTable.PageTitleAbout);
    }
}

Any page controller with high run priority example

Runs on any request and adds login panel to a pages

// Controller will be executed on any request and will be launched before other controllers (because they have Priority = 0 by default)
[Priority(-1)]
public class LoginPanelController : AsyncController
{
    public override async Task<ControllerResponse> Invoke()
    {
        return Context.Context.Authentication.User == null
            // Data from GuestPanel.tpl will be inserted into {LoginPanel} in Master.tpl
            ? new InlineTpl("LoginPanel", await TemplateFactory.LoadAsync("Shared/LoginPanel/GuestPanel"))
            // Data from LoggedUserPanelView will be inserted into {LoginPanel} in Master.tpl
            : new InlineTpl("LoginPanel", await GetView<LoggedUserPanelView>().Get(Context.Context.Authentication.User.Identity.Name));
    }
}

View example

public class LoggedUserPanelView : View
{
    public async Task<ITemplate> Get(string userName)
    {
        // Loading template from LoggedUserPanel.tpl asynchronously
        var tpl = await TemplateFactory.LoadAsync("Shared/LoginPanel/LoggedUserPanel");

        // Setting userName into {UserName} variable in LoggedUserPanel.tpl
        tpl.Add("UserName", userName);

        return tpl;
    }
}

Contributing

There are many ways in which you can participate in the project. Like most open-source software projects, contributing code is just one of many outlets where you can help improve. Some of the things that you could help out with are:

  • Documentation (both code and features)
  • Bug reports
  • Bug fixes
  • Feature requests
  • Feature implementations
  • Test coverage
  • Code quality
  • Sample applications

Related Projects

Additional extensions to Simplify.Web live in their own repositories on GitHub. For example:

License

Licensed under the GNU LESSER GENERAL PUBLIC LICENSE

simplify.web's People

Contributors

i4004 avatar ohaucke avatar waffle-iron 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

Watchers

 avatar  avatar  avatar

simplify.web's Issues

SetLoginReturnUrlFromQuery value cannot be null

System.ArgumentNullException : Value cannot be null.
Parameter name: stringToEscape
at System.Uri.EscapeDataString(String stringToEscape)
at Microsoft.Owin.ResponseCookieCollection.Append(String key, String value)
at Simplify.Web.Modules.Redirector.set_LoginReturnUrl(String value)
at Simplify.Web.Modules.Redirector.SetLoginReturnUrlFromQuery()
at Simplify.Web.Core.Controllers.ControllersRequestHandler.ProcessRequest(IDIContainerProvider containerProvider, IOwinContext context)
at Simplify.Web.Core.RequestHandler.ProcessRequest(IDIContainerProvider containerProvider, IOwinContext context)
at Simplify.Web.Owin.SimplifyWebOwinMiddleware.Invoke(IOwinContext context)

Compiler Error CS0121 - Ajax Constructor

Hi,
d1cab14 creates a new issue.
If you try to create a instance of "Ajax" var tpl = new Ajax("foobar") it can't decide which constructor (Ajax.Ajax(string, int) or Ajax.Ajax(string, string)) should be used because both are matching.

Without the "contentType = null" (public Ajax(string ajaxData, string contentType)) it can decide which constructor should be used.

Code Used Constructor
new Ajax("foobar") public Ajax(string ajaxData, int statusCode = 200)
new Ajax("foobar", 200) public Ajax(string ajaxData, int statusCode = 200)
new Ajax("foobar", "text/plain") public Ajax(string ajaxData, string contentType)

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.