Recent

Author Topic: The Brooks Framework  (Read 13806 times)

Zoran

  • Hero Member
  • *****
  • Posts: 1829
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: The Brooks Framework
« Reply #15 on: May 28, 2018, 07:36:38 pm »
There are also Michael Van Canneyt's articles on this link: https://www.freepascal.org/~michael/articles/

There you can find articles named web1, web2, and webserver. Although a bit outdated, these are well written tutorials, so don't miss them if you are starting with fcl-web!

dbannon

  • Hero Member
  • *****
  • Posts: 2786
    • tomboy-ng, a rewrite of the classic Tomboy
Re: The Brooks Framework
« Reply #16 on: May 29, 2018, 04:15:18 am »
Quote
Application.LegacyRouting := True;

No, that does not work. 'Application' is, apparently, out of scope.

So, in this example, I have chosen to make a new project, selected something like "Web Server" from the new project list. And it seems to be based on TFPWebModule1. I don't understand why there is no underlying Application object but seems no.

TFPWebModule1 does not seem to have a property 'LegacyRouting either.

So, I added Forms to uses. But then Application does not have a property called LegacyRouting nor anything similar.

I, personally, don't really need the webserver anyway, it just seemed a good idea to work through Leledumbo tutorial. And its the first and very simple example.

Davo
« Last Edit: May 29, 2018, 04:41:19 am by dbannon »
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

nummer8

  • Full Member
  • ***
  • Posts: 108
Re: The Brooks Framework
« Reply #17 on: May 29, 2018, 08:30:55 am »
Davo,

Here a fully working Hello World project as a standalone webserver.
Check the httpproject1.lpr file for the LegacyRouting parameter.
Point your browser to http://Localhost:8080
Port settings are also changeable in the same file.
Forms are not used in fp-web applications.
If you want to add something use a webmodule. (File -> New...)
 
Jos
 
edit: updated the project, added the missing file
« Last Edit: May 30, 2018, 08:15:12 am by nummer8 »

Leledumbo

  • Hero Member
  • *****
  • Posts: 8746
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: The Brooks Framework
« Reply #18 on: May 29, 2018, 10:26:49 pm »
Quote
Application.LegacyRouting := True;

No, that does not work. 'Application' is, apparently, out of scope.

So, in this example, I have chosen to make a new project, selected something like "Web Server" from the new project list. And it seems to be based on TFPWebModule1. I don't understand why there is no underlying Application object but seems no.

TFPWebModule1 does not seem to have a property 'LegacyRouting either.

So, I added Forms to uses. But then Application does not have a property called LegacyRouting nor anything similar.

I, personally, don't really need the webserver anyway, it just seemed a good idea to work through Leledumbo tutorial. And its the first and very simple example.

Davo
It's a global variable (available from any of the server unit: fpcgi, fpfcgi or fphttpapp), access it in the program source (.lpr), not the module units (.pas / .pp), even if it's possible I don't consider it a good practice.

dbannon

  • Hero Member
  • *****
  • Posts: 2786
    • tomboy-ng, a rewrite of the classic Tomboy
Re: The Brooks Framework
« Reply #19 on: May 30, 2018, 05:22:52 am »
Here a fully working Hello World project as a standalone webserver.
Check the httpproject1.lpr file for the LegacyRouting parameter......

Thanks Joz, yep, I put that line in the lpr file and it compiled and worked as expected. Thanks.
By the way, your zip did not include the .lpi file, needed to build it. But easy to paste the relevant line, "Application.LegacyRouting := True; " into the .lpr file of my (absolute minimal) project and, as you said, it does work.

Thanks !
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

dbannon

  • Hero Member
  • *****
  • Posts: 2786
    • tomboy-ng, a rewrite of the classic Tomboy
Re: The Brooks Framework
« Reply #20 on: May 30, 2018, 05:34:26 am »
It's a global variable (available from any of the server unit: fpcgi, fpfcgi or fphttpapp), access it in the program source (.lpr), not the module units (.pas / .pp), even if it's possible I don't consider it a good practice.

Sorry Leledumbo, can you please clarify, do you mean you consider using this switch at all to be bad practice or is the bad practice  just using it in a .pas or .pp file ?

When I used it in my .lpr file, things started to work.

Does that  switch indicates something is wrong ?  I'm guessing fcl-web uses an 'out of date' model, replaced in Lazarus, when we request "LegacyRouting" - is this a viable, long term solution ? if its a good thing, should that switch be patched into the Lazarus code base ?

Davo
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

nummer8

  • Full Member
  • ***
  • Posts: 108
Re: The Brooks Framework
« Reply #21 on: May 30, 2018, 08:29:42 am »
Davo,

The switch is not an indication that there is something wrong.
It is just a switch to make it possible to choose from two different routing systems for your project.
Just set it in the program source (and no where else).
To get the other examples running make the same change to the program source.

Jos
 

Leledumbo

  • Hero Member
  • *****
  • Posts: 8746
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: The Brooks Framework
« Reply #22 on: May 31, 2018, 05:45:55 am »
Sorry Leledumbo, can you please clarify, do you mean you consider using this switch at all to be bad practice or is the bad practice  just using it in a .pas or .pp file ?
The latter.
Does that  switch indicates something is wrong ?  I'm guessing fcl-web uses an 'out of date' model, replaced in Lazarus, when we request "LegacyRouting" - is this a viable, long term solution ? if its a good thing, should that switch be patched into the Lazarus code base ?
No, nothing wrong. It's just the old way of routing is unnecessarily complex and is tailored too much for RAD use. Lazarus doesn't alter anything to fcl-web (apart from providing a wizard to create fpWeb project easily), it's fcl-web (fpWeb actually) itself that is evolving. This should be the long term solution, hence the LegacyRouting property is off by default, to make further new usage uses the new routing immediately instead of maintaining backward compatibility with old projects (which is also a one liner change).

dbannon

  • Hero Member
  • *****
  • Posts: 2786
    • tomboy-ng, a rewrite of the classic Tomboy
Re: The Brooks Framework
« Reply #23 on: May 31, 2018, 03:03:03 pm »
OK, thanks heaps folks for the help you have given me with getting this going. I will be taking my project into this space, one way or another, in the not to distant future.

And as I mentioned, hope I can contribute some documentation along the way.

Davo
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

Leledumbo

  • Hero Member
  • *****
  • Posts: 8746
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: The Brooks Framework
« Reply #24 on: May 31, 2018, 09:26:23 pm »
And as I mentioned, hope I can contribute some documentation along the way.
Pull requests to my tutorial is acceptable :)

silvioprog

  • Newbie
  • Posts: 6
Re: The Brooks Framework
« Reply #25 on: November 26, 2018, 04:10:58 pm »
I'm looking to build my next web-app using the Brook Framework, but the documentation site is unreachable. 
I'd like the official "Getting Started" documents to start reading up how to use it.
I have already installed the latest Brook framework (2018-May-09 version) using the Online Package Manager just a few minutes ago.

https://brookframework.org/doc/index.html

I can only find really old posts by Silvio Clécio in the forum.

Hi RedOctober,

I don't often use forums, but after found this topic via Google I reopen my forum account to answer (even late) your questions and explain regarding Brook framework.

Today, Brook is in beta version 5.0 (codename Tardigrade). It compiles in Delphi and Free Pascal and has been successfully tested on these OSes:

Windows [32/64]
Linux [32/64]
Raspbian [any]
Android [19+]

(this answer shows the systems which it has been tested constantly: https://github.com/silvioprog/brookframework/issues/160#issuecomment-440375746)

Any previous version of Brook is Free Pascal-only, and the latest release for it with respective patches are available here: https://github.com/silvioprog/brookframework/releases/tag/v4.0.0 .

Since Brook 5.0 was written from scratch, it is practically a new project (the reason for having a new major version), that don't depends on fcl-web (since it needs to run on Delphi too), so its documentation, examples and tests are being developed, and a new issue about that was opened here with a respective To-Do project: Issue: https://github.com/silvioprog/brookframework/issues/162 / To-Do project: https://github.com/silvioprog/brookframework/projects/1.

Some Q/A to make clear about Brook framework (and me) to avoid misunderstandings:

Q: Why Brook now uses a C library?
A: At least someone asking the reason why now it uses a C library! Brook needed to be high-performance without depending on external web servers (Apache, Nginx, IIS or kernel mode driver like http.sys etc.), and there is no any HTTP server in pure Pascal which reaches it: https://github.com/risoflora/libsagui/tree/master/examples/benchmark . I've been developed business solutions for years, and it has been more productive to use a small (about 140 kB) C library instead of an entire third party web server, making easier the debugging at production stage, no configuration, low or no cost when required support.

Q: Who is the author(s) of the library used by Brook?
A: The GNU community and me.

Q: What features / license of the library?
A: Event-driven; One thread per request; Thread pool (very recommend for large demand of requests); High-performance path routing supporting compiled Regex using Just-in-time optimization (JIT); Entry-points matching using binary search; HTTPS support using GnuTLS (TLS 1.3); Basic authentication; Upload/download streaming by payload (JSON, XML transferring) and file (large data transferring like videos, images, binaries and so on); Fields, parameters, cookies, headers and any key-value list under hash table structure . The library is under LGPL 3.

Q: Did silvioprog abandon Pascal?
A: As I said recently on Twitter (which I rarely use), I never left Pascal!!!: https://twitter.com/silvioprog/status/1061124155280711680 . I can't understand why people are thinking it about me, since I've constantly contributed to FPC/Lazarus by sending patches via Mantis.

Q: Was Brook framework abandoned?
A: Not by me! ;-) But, unfortunately, I have seen people that even don't know the project using social network to discourage Brook.

Q: Why few activity in Brook commits?
A:
(me): Because I'm working in other important parts that will be used in Brook 5.1, for example: RTTI.Invoke() assembly for System V ABI (Linux64): https://github.com/silvioprog/rtti.invoke ; I joined to Pas2JS (which I would like to integrate to Brook 5+), so I'm working on it too: https://bugs.freepascal.org/view.php?id=34524 (and several other patches I've sent to the Lazarus/FPC team); I'm studying real-time applications to support it in Brook. Some people send me e-mails / called me requesting training / paid support for dedicated time (I do complementar works like teaching development using Brook, 8-bit microcontrollers, embedded/electronic solutions etc.), and I spend long time answering / training them. And other things of any person spends time, like family, company etc.
(other maintainers): Currently, there is some people requesting help/documentation/features at issues page. For while, I'm the only maintainer working in the current version, but I believe that will have more people working on Brook as soon the version 5.0 is released and published in Delphi communities too (including its GetIt tool). I'll search partners for Brook too, maybe joining to some event like 'Delphi developers day' or a Lazarus one.

Q: Why new Brook was written from scratch?
A: Just to offer the same classes to compile in Delphi or Free Pascal.

Q: Does Brook 5 have a persistence layer?
A: Not yet. Maybe in Brook 5.1, using drivers directly or a single small C library.

Q: What is 5.0 & 5.1?
A: 5.0 = current version on trunk, just waiting documentation/tests to be released, but already massively tested in production in many customers of our company; 5.1 = next version after 5.0, supporting dynamic class routing and maybe real-time applications plus persistence.

Extra Q: Does Brook 5 have web-sockets support?
A: Not yet. Maybe in Brook 5.1, since it will support real-time applications.

I can't imagine a web application in the real world working without a database and/or any security layer. So, how the purely Pascal people that don't like (or hates) C libraries does, by rewriting the database low-level driver in pure Pascal from scratch? Or rewriting complex code for TLS in pure Pascal? No, of course. They uses C libraries and distribute them! Particularly, I'm not purist, so I don't have any resistance by using a C library or anything that help me to solve the complex problems day after day at company, the only restrictions I have using anything (a car, a bike, a motorcycle or a software...) depends as so good it is, if it has support and really solve the problem efficiently. For example, I don't like assembly so much, but I know it, so I used it to solve a problem in the FPC RTL: https://github.com/silvioprog/rtti.invoke/blob/master/invoke_unix64.inc#L50 .

I'll stay not much active on forum, precisely because I'm working to contribute to FPC improving its RTL (specially the RTTI part), since many RTL features are present only on Delphi and I would like to use them on FPC too. Anyway, if you want to know what new features are present in Brook 5 and which are the advantages of using them, I'll be glad to answer via Brook community at https://plus.google.com/u/0/communities/101133820055678331036 .
« Last Edit: November 26, 2018, 04:24:08 pm by silvioprog »

RedOctober

  • Sr. Member
  • ****
  • Posts: 452
Re: The Brooks Framework
« Reply #26 on: November 26, 2018, 05:20:25 pm »
Thank you Slivio!  Those were all the answers I was hoping for!  ( I am like you, with regards to not being averse to using something, as long as it works well.  I don't work in C but I will gladly use a C Library if it works best and gets the job done quickly )
« Last Edit: November 26, 2018, 06:34:00 pm by RedOctober »

Hydexon

  • Full Member
  • ***
  • Posts: 170
Re: The Brooks Framework
« Reply #27 on: November 26, 2018, 07:20:35 pm »
Quote
Q: Does Brook 5 have a persistence layer?
A: Not yet. Maybe in Brook 5.1, using drivers directly or a single small C library.

What about tiOPF?

Quote
Extra Q: Does Brook 5 have web-sockets support?
A: Not yet. Maybe in Brook 5.1, since it will support real-time applications.

Dang, there's some workaround to implement Websockets?, i wanted to use Brook/FPC for an freelance project instead of Java Spring (my client wants any language minus PHP).

Also i wanted to ask, the performance of Brooks Frameworks is really good?, i mean compared with big frameworks of other languages such Java Spring, PHP CakePHP/Laravel, or Ruby on Rails?, i think the FPC being native without VM need and doesn't have an GC can get an considerable boost i think (but have to be really careful about memory management)
Lazarus 1.0.4 Stable - FPC 2.6.0 - gtk2 | Linux Mint 14 Nadia | GNOME Shell 3.6.2 - Awesome | Intel x86 | HP Mini 1020-LA Netbook (old)
Lazarus 2.0.2 Stable - FPC 3.0.2 - Windows | Lenovo IdeaPad Y

silvioprog

  • Newbie
  • Posts: 6
Re: The Brooks Framework
« Reply #28 on: November 26, 2018, 11:33:25 pm »
Quote
What about tiOPF?

I've been hearing that it is a good project, so we should check it soon too. Anyway, any project licensed by GNU, BSD or MIT allowing to generate SQL statements from a custom dynamic scheme will be considered as good option too.

Quote
Dang, there's some workaround to implement Websockets?, i wanted to use Brook/FPC for an freelance project instead of Java Spring (my client wants any language minus PHP).

The library core already allows to handle "Connection: Upgrade", so it is possible to support websockets, upgrade to TLS and all kinds of other protocol switches (via HTTP response code 101), but we want to make it easy for the final programmer, probably adding five or six new functions to the library API.

Quote
Also i wanted to ask, the performance of Brooks Frameworks is really good?, i mean compared with big frameworks of other languages such Java Spring, PHP CakePHP/Laravel, or Ruby on Rails?, i think the FPC being native without VM need and doesn't have an GC can get an considerable boost i think (but have to be really careful about memory management)


There are people running 100,000 requests/s on a single system using the library core, and I've been doing my own tests enabling its thread-pool and using all processors (CPU cores) currently online (available). Anyway, you should check it on your infrastructure, preferably in a real scenario with machines connected to a server via network. I can help you explaining (via Brook community on Google+) how to configure a good environment to do some benchmarks closest as possible to the production reality (never use localhost in the final tests).
« Last Edit: December 01, 2018, 05:50:39 am by silvioprog »

 

TinyPortal © 2005-2018