Home
Softono
lara

lara

Open source Apache-2.0 C#
158
Stars
9
Forks
10
Issues
7
Watchers
2 months
Last Commit

About lara

Lara is a lightweight C framework for developing web user interfaces using server-side rendering. Designed as a simpler and more efficient alternative to Blazor, Lara requires only a NuGet package installation without needing a full SDK. It enables developers to build interactive web applications where browser events, such as clicks, trigger server-side execution. The framework processes these events, updates the server-side model, and sends minimal JSON diff messages to synchronize the client view. Lara supports real-time data binding and event handling through express C syntax, allowing components to modify HTML elements directly. It can be launched as a standalone web server or integrated into existing ASP.NET Core applications via middleware. Additionally, Lara facilitates the creation of desktop applications by working with cross-platform container projects like Electron.js, Chromely, and NeutralinoJS. The framework is cross-platform, open-source under Apache 2.0, and provides a streamlined workflow for

Platforms

Web Self-hosted Windows

Languages

C#

Links

Lara Web Engine

License: Apache 2.0 NuGet version Download count Build Status Coverage Status

Lara is a server-side rendering framework for developing web user interfaces using C#.

"It is similar to server-side Blazor, but is much more lightweight and easier to install. For example, while any type of Blazor requires a whole SDK, Lara is just a NuGet package." ScientificProgrammer.net

Sample application

using Integrative.Lara;
using System;
using System.Threading.Tasks;

namespace SampleApp
{
    public static class Program
    {
        public static async Task Main()
        {
            // create and start application
            const int port = 8182;
            using var app = new Application();
            app.PublishPage("/", () => new MyCounterComponent { Value = 5 });
            await app.Start(new StartServerOptions { Port = port });

            // print address on console
            var address = $"http://localhost:{port}";
            Console.WriteLine($"Listening on {address}/");

            // helper function to launch browser (comment out as needed)
            LaraUI.LaunchBrowser(address);

            // wait for ASP.NET Core shutdown
            await app.WaitForShutdown();
        }
    }

    internal class MyCounterComponent : WebComponent
    {
        private int _value; // triggers PropertyChanged event
        public int Value { get => _value; set => SetProperty(ref _value, value); }

        public MyCounterComponent()
        {
            ShadowRoot.Children = new Node[]
            {
                new HtmlDivElement() // on PropertyChanged, assigns InnerText
                    .Bind(this, x => x.InnerText = Value.ToString()),
                new HtmlButtonElement
                    { InnerText = "Increase" }
                    .Event("click", () => Value++)
            };
        }
    }
}

Adding Lara to an existing web server application

To add Lara to an existing ASP.NET Core server, add to the Startup class or equivalent:

private readonly Application _laraApp = new Application();

public void Configure(IApplicationBuilder app)  
{  
    app.UseLara(_laraApp, new LaraOptions
    {
        // configuration options
    });
} 

Creating Desktop applications

To create a desktop container for your web app, here's a few options:

Getting started

There's no need to download this repository to use Lara, instead, there's a NuGet package.

Check out the wiki documentation

How does Lara work?

Whenever the browser triggers a registered event (e.g. click on a button), it sends to the server a message saying that the button was clicked. The server executes the code associated with the event, manipulating the server's copy of the page, and replies a JSON message with the delta between server and client.

How to contribute

Please send feedback! Issues, questions, suggestions, requests for features, and success stories. Please let me know by either opening an issue. Thank you!

If you like Lara, please give it a star - it helps!

Credits

Thanks to JetBrains for the licenses of Rider and DotCover.

JetBrains