Skip to content
Lara is a lightweight cross-platform C# library for Web UI development with server-side rendering.
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src Fixed #33. Added new method for deserialization passing type as param… Jul 11, 2019
support added feedback html files Jun 9, 2019
.gitignore hide inherited members from documentation Jun 20, 2019
LICENSE Create LICENSE May 14, 2019
README.md added gitter channel Jun 27, 2019

README.md

Lara Web Engine

Lara is a lightweight, high-performance cross-platform C# library for Web UI development with DOM manipulation and server-side rendering.

The purpose of Lara is to give you full control of the HTML document tree from the server in C#.

  • Cross-Platform: .NET Standard and runs on Windows, Linux, and MacOS.
  • Web UI: Create HTML5 web applications with full control of the DOM tree in C#.
  • Server-side rendering: The server keeps a virtual copy of the page and flushes the modifications to the browser.

Lara can be used to develop either websites or desktop apps with an HTML5 frontend.

The source code contains a sample project that is also available as a separate repository.

We welcome questions and feedback! Our Gitter channel is here and we also have a general feedback form here.

Sample application

To create a web page:

  • Create a class that implements the interface 'IPage'
  • Call LaraUI.Publish(...) to make your page available

Lara uses async/await to allow for high server throughput. If you're new to these, simply follow the examples that return 'Task.CompletedTask' at the end.

Example:

namespace SampleProject
{
    class Program
    {
        static async Task Main()
        {
            Console.WriteLine("Starting...");

            // associate home address with code that creates home page
            LaraUI.Publish("/", () => new MyPage());

            // start web server using default settings on a dynamic port number
            var host = await LaraUI.StartServer();

            // write address in console
            string address = LaraUI.GetFirstURL(host);
            Console.WriteLine($"Server listening in {address}.");

            // launch browser tab (alternatively, the user can navigate to the address)
            LaraUI.LaunchBrowser(address);

            // wait for termination
            Console.WriteLine("Press Ctrl+C to terminate");
            await host.WaitForShutdownAsync();
        }
    }

    class MyPage : IPage
    {
        int counter = 0;

        public Task OnGet(IPageContext context)
        {
            var button = Element.Create("button");
            var text = new TextNode { Data = "Click me" };
            button.AppendChild(text);
            button.On("click", app =>
            {
                counter++;
                text.Data = $"Clicked {counter} times";
                return Task.CompletedTask;
            });
            context.Document.Body.AppendChild(button);
            return Task.CompletedTask;
        }
    }
}

Integrating Lara into your existing web server

The example above calls into Lara's StartServer() method to create a default web host.

Alternatively, you can and add Lara as one more service with the following line:

app.UseLara(options);

Developing a desktop application

Here you need to choose a tool to load your locally-hosted website inside a desktop window. Some options available:

  • Creating an electron app using electron-cgi (recommended). This seems to be the most resilient way to run a web desktop app. It comes at the cost of having to distribute electron with nodejs.
  • Using Chromely. Currently supports Windows and Linux. Their Windows version based on CefSharp works very well.

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.

Feedback

We'd love to hear your feedback. Write to us here.

You can’t perform that action at this time.