Simplify.Web is an open-source, lightweight, fast and highly customizable server-side .NET web-framework based on ASP.NET Core for building HTTP based web-applications, RESTful APIs etc.
Framework 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
Can be hosted:
- The same way as an ApsNetCore MVC application (On IIS, or as a console application)
- Inside a windows service
- Comes as Microsoft.AspNetCore 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
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).
[Get("api/v1/weatherTypes")]
public class SampleDataController : Controller2
{
private static readonly string[] Summaries =
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};
public ControllerResponse Invoke()
{
try
{
return Json(items);
}
catch (Exception e)
{
Console.WriteLine(e);
return StatusCode(500);
}
}
}
[Post("api/v1/sendMessage")]
public class SampleDataController : Controller2<SampleModel>
{
public 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; }
}
// 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 StaticTpl("Static/About", StringTable.PageTitleAbout);
}
}
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));
}
}
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;
}
}
Below is the list of sample applications showing different variations of Simplify.Web usage:
- Only as an API backend with Angular + Bootstrap UI SPA
- Kestrel-based Application with backend HTML generation, localization, authentication
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
Additional extensions to Simplify.Web live in their own repositories on GitHub. For example:
- Simplify.Web.Json - JSON serialization/deserialization
- Simplify.Web.Postman - Postman collection and environment generation
- Simplify.Web.Swagger - Swagger generation for controllers
- Simplify.Web.Multipart - multipart form model binder
- Simplify.Web.MessageBox - non-interactive server side message box
- Simplify.Web.Templates - .NET projects templates
Licensed under the GNU LESSER GENERAL PUBLIC LICENSE