Git Product home page Git Product logo

fpcwebapp's Introduction

drawing

Barebones Web Server in FPC/Lazarus

Building a full-featured webserver for an htmx based web application needs a manageable server codebase = Easy to setup, easy to read, easy to refactor with easy/quick database access. Object Pascal is overlooked by reviewers and webdevs. It is probably because there are not many tutorial videos that showcase the wide capbabilities of the language rather than a flaw in the technology.

Requirements

Lazarus IDE

Install the following packages in Lazarus in this order:

  1. Rhl
  2. Brook Tardigrade. You will also need to install the dll/so for libsagui. Instructions are on their github page
  3. Sugar for FP/Lazarus. This gives you a lot of syntax sugar to quicky build html pages and serve.

Documentation is coming soon.

Objective

Use this project as a starting point for any web app you are thinking of building. It has the following things out of the box:

  1. Simple GUI based mechanism to define, develop, debug and maintain web routes.
  2. A file server component that server on /assets. It implements ETag.
  3. (coming) File upload capability
  4. Htmlbuilder where you can programatically generate complex nesting, including inline styles. There is inbuilt support for VueJS (browser). You can generate html snippets very easily as follows:
function summarySection: string;
begin
    with THtmlDiv.Create do begin
        try
            h1('Overview);
            div_('This is a test section);
            h2('Section 1');
            // Shows off method chaining
            div_('This is sub section for this topic')
                .class('ui blue text')
                .setAttr('')
                .div_('This is a nested div');

            Result := html(); // Generates the Html code
        finally
            free;
        end;
    end;
end;
  1. A powerful wrapper for SQLite where you can define a complex schema in a Pascal unit from which we can programatically generate the SQL code necessary to create and initialize the database. The wrapper also allows you to manage multiple database files (with something like:

dbModule('thisdata.db').put(_tableName, _rowID, _field, value)

which updates a field in a table.

This project showcases wonderful the developer experience of building a complex application in FPC/Lazarus and to highlight its cross-platform capabilities. You can compile the code on Windows, Mac and Linux without having to tweak it too much. The final binary is blazingly fast and can run efficently on a single-core, 1GB RAM virtual machine.

As a language, Object Pascal compares favourably with other languages in terms of how easy it is to get started with it. Where it shines, afaik, is in the inherent syntax structure that offers many ways to organize your code and navigate through different sections. It is orders of magnitude easier to figure out the logic in a large Object Pascal project (Lazarus, Delphi) than any others that I've delved into.

This project has only been possible because of the dedication and persistance of the FPC/Lazarus team, the amazing micro-services framework for FPC Brook Tardigrade, the cryptography library Rhl.

fpcwebapp's People

Contributors

stanley643212 avatar

Watchers

 avatar

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.