Lazarus

Programming => Packages and Libraries => Topic started by: RedOctober on May 25, 2018, 09:36:31 pm

Title: The Brooks Framework
Post by: RedOctober on May 25, 2018, 09:36:31 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.
Title: Re: The Brooks Framework
Post by: Zoran on May 25, 2018, 10:01:17 pm
See:
https://github.com/silvioprog/brookframework/issues/148 (https://github.com/silvioprog/brookframework/issues/148)
Title: Re: The Brooks Framework
Post by: RedOctober on May 26, 2018, 01:24:37 am
Hi Zoran, thanks.  I now have the reference docs.  I'm wondering if there is a "How to get started" book somewhere, especially for the most recent stable version (3.9.9). 

Platform:  Windows Server 2016 Essentials, Lazarus 1.8.2, FPC 3.0.4

I was able to load the chat demo, I click Run and a window quickly flashes and disappears before I can read it.  Not sure what is wrong, or where to go next. 

Also, I need Brook to connect to the Firebird RDBMS.  Does anyone know if that's possible? 
Title: Re: The Brooks Framework
Post by: valdir.marcos on May 26, 2018, 06:27:07 am
Also, I need Brook to connect to the Firebird RDBMS.  Does anyone know if that's possible?
Yes.
https://www.firebirdnews.org/brook-a-new-web-framework-for-freepascallazarus-with-firebird-support/
Title: Re: The Brooks Framework
Post by: Leledumbo on May 26, 2018, 04:11:39 pm
Also, I need Brook to connect to the Firebird RDBMS.  Does anyone know if that's possible?
Brook is not tied to any DB libraries nor it has its own. You are free to use anything that can connect to any DBMS. Well, Silvio did develop the now abandoned dOPF (but I still use and extend it) which is a little OPF with SQLdb backend (but the structure should allow you to write another backend) so you might want to use that. Using SQLdb directly is also possible, you just need to do it by hand instead of drag n drop-ing component.
Title: Re: The Brooks Framework
Post by: RedOctober on May 27, 2018, 12:08:21 am
Hi valdir.marcos. The link https://brookframework.org/  is dead.  It shd be removed from the Firebird web page.

Hi Leledumbo.  I don't know what a "OPF" is.  Once some one gets me a "How to get started" document, then I'll be back to ask you more.

Does anyone use Brook? Seems like it's been abandoned.  Version 4 is supposed to come out some time, but it's been 4 years since the announcement was made.  I'm kind of hesitant to use something that's been abandoned and hardly anyone is using it, no matter how good it is.
Title: Re: The Brooks Framework
Post by: Leledumbo on May 27, 2018, 12:30:43 am
Hi Leledumbo.  I don't know what a "OPF" is.  Once some one gets me a "How to get started" document, then I'll be back to ask you more.
Google: Object Persistence Framework. Can be somewhat interchanged with Object Relational Mapping, though they're complementing each other conceptually.
Does anyone use Brook? Seems like it's been abandoned.  Version 4 is supposed to come out some time, but it's been 4 years since the announcement was made.  I'm kind of hesitant to use something that's been abandoned and hardly anyone is using it, no matter how good it is.
I do, version 3 though as I don't want to use C library in my code. But I might port the code to latest fpWeb, since the routing is no longer as overly complicated as it was. In fact, Brook 3 layer (on top of fcl-web) looks thicker than fpWeb now. No change to dOPF, though, as I haven't found a free open source replacement that's as easy to use nor I have successfully written my own.
Title: Re: The Brooks Framework
Post by: dbannon on May 27, 2018, 04:44:32 am
... Brooks...... But I might port the code to latest fpWeb, ....

OK, now you have mentioned Brooks and fpWeb in the same message. For some time I have been thinking I need to look at these packages. However, neither appear to have any authentication model build it. Is that because its not possible/practical, no one has bothered yet or is authentication (and authorization) more appropriately done at another level ?

Davo

(Sorry for hijacking your thread redoctober)
Title: Re: The Brooks Framework
Post by: Leledumbo on May 27, 2018, 06:06:37 am
However, neither appear to have any authentication model build it. Is that because its not possible/practical, no one has bothered yet or is authentication (and authorization) more appropriately done at another level ?
Both are thin framework on top of fcl-web libraries, in the sense that neither has other facilities other than routing handler. fcl-web is, however, is a lot richer. It has libraries for JWT, OAuth 2, HTTP/2, JSON-RPC, etc. It's just they come only with examples, no documentation.
Title: Re: The Brooks Framework
Post by: dbannon on May 27, 2018, 06:28:07 am
OK, thanks for that Leledumbo, I did not pick up fcl-web coud do, eg OAuth2. I had looked through your PDF and browsed the Laz examples dir. Where should I look for the fcl-web examples ?

(I take a lot of notes while writing so, sometimes, those notes can form a start of some documentation....)

Davo
Title: Re: The Brooks Framework
Post by: Leledumbo on May 27, 2018, 10:52:39 am
Where should I look for the fcl-web examples ?
In the source code folder.
Title: Re: The Brooks Framework
Post by: dbannon on May 27, 2018, 11:52:14 am
Ah, you mean /usr/share/fpcsrc/3.0.4/packages/fcl-web/examples ?

I was looking in the Lazarus tree, but that now makes sense.

Yep, thanks   Leledumbo, that looks like a good start. I need to do some reading !

Davo
Title: Re: The Brooks Framework
Post by: dbannon on May 27, 2018, 01:43:52 pm

Edit : I really should have created a new thread, this is about fcl-web - sorry !

OK, I tried following the PDF tutorial, it installed fine, rebuilt IDE, extra options on the New Project file. So I tried first example. The HTTP Server Application, "hello world".

It builds and launches fine and I note that you expect to see a number of handled exceptions but all I see is one (presumably handled) and then I get a
----------------------------------
httpproject1: ERROR
The application encountered the following error:
    Error: Not found
    Stack trace:
    $000000000049D460
    $000000000049CA0F
----------------------------------
in the browser. The one exception shows us -

Project httpproject1 raised exception class 'EHTTPRoute' with message
Not Found

Interestingly, the binary is not in project directory but down in lib, if I run it from command line, same result in browser window but as expected, no exception.

Now, I cannot trace execution back through fcl-web because its compiled without debug info so I am sort of lost as to how to proceed. 

Can I remove the package, rebuild it "in user space" for want of a better term so I can step through and find out just where the problem lies ?

Davo
Title: Re: The Brooks Framework
Post by: nummer8 on May 27, 2018, 03:14:52 pm
There is a new routing system in place.
To get the fp-web examples working use the following line in the application.
Application.LegacyRouting := True;

Jos
Title: Re: The Brooks Framework
Post by: dbannon on May 28, 2018, 01:00:47 am
Thanks Jos, I may not get a chance to try it out for a day or so so thanks in advance !

If that works, I'll update the wiki but, of course, not the PDF. I guess 'we' need to know a bit more about that issue ?  Do you know how the 'new' routing model works ? I assume it should be used ?

Davo
Title: Re: The Brooks Framework
Post by: Zoran 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/ (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!
Title: Re: The Brooks Framework
Post by: dbannon 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
Title: Re: The Brooks Framework
Post by: nummer8 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
Title: Re: The Brooks Framework
Post by: Leledumbo 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.
Title: Re: The Brooks Framework
Post by: dbannon 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 !
Title: Re: The Brooks Framework
Post by: dbannon 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
Title: Re: The Brooks Framework
Post by: nummer8 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
 
Title: Re: The Brooks Framework
Post by: Leledumbo 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).
Title: Re: The Brooks Framework
Post by: dbannon 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
Title: Re: The Brooks Framework
Post by: Leledumbo 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 :)
Title: Re: The Brooks Framework
Post by: silvioprog 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 .
Title: Re: The Brooks Framework
Post by: RedOctober 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 )
Title: Re: The Brooks Framework
Post by: Hydexon 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)
Title: Re: The Brooks Framework
Post by: silvioprog 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).
TinyPortal © 2005-2018