Lazarus

Programming => Networking and Web Programming => Topic started by: Leledumbo on July 14, 2015, 01:13:40 pm

Title: [Tutorial] Basic fpWeb Tutorial Article
Post by: Leledumbo on July 14, 2015, 01:13:40 pm
I proudly present my latest writing: Basic fpWeb Tutorial (https://dl.dropboxusercontent.com/u/22124591/Docs/fpwebtutorial.pdf).
This article covers basic usage of fpWeb such as request flow & handling, modules, actions, cookies and sessions. Feel free to comment for improvement, but it's better to send patches here (https://bitbucket.org/leledumbo/books) ;)
Title: Re: [Tutorial] Basic fpWeb Tutorial Article
Post by: bee on July 15, 2015, 05:17:51 am
Great job, bro. Thank you. With just one suggestion... provide example(s). :)
Title: Re: [Tutorial] Basic fpWeb Tutorial Article
Post by: motaz on July 15, 2015, 10:07:48 am
This is a well written document about fpWeb. I always prefer default packages, and without this document we couldn’t know about it's fpWeb features
Title: Re: [Tutorial] Basic fpWeb Tutorial Article
Post by: exdatis on July 15, 2015, 10:12:52 am
Thank you very much!
Title: Re: [Tutorial] Basic fpWeb Tutorial Article
Post by: nomorelogic on September 04, 2015, 07:26:03 pm
I translated the tutorial in Italian.
There is still a bit 'of work to do (translate images) but there we are.

I'm not a professional translator, criticism is welcome  :)


Edit:
ops...
https://bitbucket.org/nomorelogic/traduzioni (https://bitbucket.org/nomorelogic/traduzioni)
Title: Re: [Tutorial] Basic fpWeb Tutorial Article
Post by: Trenatos on September 04, 2015, 11:15:38 pm
I've only had a chance to speed-read through it, but this looks great!

Instead of skimming and not explaining important details, it seems that you cover the basics properly, how to use sessions, cookie, scope, post/get, modules, etc.

I will definitely be spending some time checking this out.
Title: Re: [Tutorial] Basic fpWeb Tutorial Article
Post by: Trenatos on September 04, 2015, 11:31:44 pm
Hm, actually, I ran into a problem.

After creating a new application, and trying to start it as described, I get an error when I visit the page:  TCustomHTTPModule not found
Title: Re: [Tutorial] Basic fpWeb Tutorial Article
Post by: Leledumbo on September 05, 2015, 10:26:56 am
Hm, actually, I ran into a problem.

After creating a new application, and trying to start it as described, I get an error when I visit the page:  TCustomHTTPModule not found
Please be specific, I'm not an oracle. I can't see what you code, how you run it, etc.
Title: Re: [Tutorial] Basic fpWeb Tutorial Article
Post by: eny on September 05, 2015, 11:32:48 am
Great introduction!
Would be nice if it would be integrated in the Wiki though (http://wiki.lazarus.freepascal.org/fcl-web).
Title: Re: [Tutorial] Basic fpWeb Tutorial Article
Post by: Trenatos on September 05, 2015, 07:09:59 pm
Hm, actually, I ran into a problem.

After creating a new application, and trying to start it as described, I get an error when I visit the page:  TCustomHTTPModule not found
Please be specific, I'm not an oracle. I can't see what you code, how you run it, etc.

Sorry about that. It seems I missed the part about ignoring all the exceptions.

When I do that, it works and I see the text in browser.
Title: Re: [Tutorial] Basic fpWeb Tutorial Article
Post by: cappe on November 19, 2015, 05:55:33 pm
Thank you
Title: Re: [Tutorial] Basic fpWeb Tutorial Article
Post by: tigerA15 on November 30, 2015, 05:12:02 am
that's great.
Title: Re: [Tutorial] Basic fpWeb Tutorial Article
Post by: kveroneau on February 02, 2016, 12:26:44 am
Great tutorial, the example code provided is very helpful at explaining how to use fpWeb, especially for someone who is new to FP/Lazarus.

I would like to point out that I did reference the source code for some additional help, such as DefaultModuleName, which is useful if you have multiple modules, but want "/" to still do something.

Some stuff I'd love covered in a future fpWeb tutorial would be:

 * What are the exceptions we are seeing in Lazarus when we run our app?  Are we suppose to trap these exceptions, where/how do we trap them?
 * How does the serving of static files work?  For dev, it's nice to have the dev server serve JavaScript/CSS/images, but in a production environment, Nginx/Apache/CDN should really serve these.
 * How could you override the default request handler?  Currently the URI system is /module/action, with no mentioning of any customization.
 * How can you send out another HTTP response code?  Such as 403, or a 302 to the browser?
 * An example of how to override Application.OnGetModule would be great!
 * How to handle exceptions in production, such as sending out an email to the admin with the exception text.
 * Can the exceptions during development be set to be more human to read?  Currently, the stack trace reads like machine code.
 * More example code on using sessions, and how the browser cookie is set for these sessions.
 * Examples on how to use the other lazweb module types: Web DataProvider, Web JSON-RPC, Web Ext.Direct, HTML Web

I'll see about researching into these myself in the meantime.  I am currently debating on using Pascal for future web projects, especially where performance might be needed.  When comparing how fast a page loads in Pascal to dynamic languages like Python, it really shows a speed boast, as there's no more bytecode VM in the middle.  I'd personally like to do a basic benchmark to say compare fpWeb with a Python microframework like Bottle.py.
Title: Re: [Tutorial] Basic fpWeb Tutorial Article
Post by: Leledumbo on February 02, 2016, 01:11:59 am
* What are the exceptions we are seeing in Lazarus when we run our app?  Are we suppose to trap these exceptions, where/how do we trap them?
None, unless it's from user own code. The tips and tricks section mentions how to trap this and displays appropriate error page instead of the default stack trace.
* How does the serving of static files work?  For dev, it's nice to have the dev server serve JavaScript/CSS/images, but in a production environment, Nginx/Apache/CDN should really serve these.
Hmm... I did mention the dialog but doesn't go deep enough of how it works. Noted.
* How could you override the default request handler?  Currently the URI system is /module/action, with no mentioning of any customization.
Application.OnGetModule should be exploited.
* How can you send out another HTTP response code?  Such as 403, or a 302 to the browser?
I missed that one. Noted. In the meantime, try setting Response.Code.
* An example of how to override Application.OnGetModule would be great!
I consider custom routing as not "basic", let me think about it.
* How to handle exceptions in production, such as sending out an email to the admin with the exception text.
This should be out of the tutorial since the custom exception handling has been covered and email sending is not part of fpWeb feature.
* Can the exceptions during development be set to be more human to read?  Currently, the stack trace reads like machine code.
Again, back to tips and tricks on custom exception handler.
* More example code on using sessions, and how the browser cookie is set for these sessions.
More? What's missing? How the browser cookie is set could be added, it's just informational (see FPWebSession in your browser's cookie).
* Examples on how to use the other lazweb module types: Web DataProvider, Web JSON-RPC, Web Ext.Direct, HTML Web
Definitely not basic. TBH, I'm not sure on how to use half of them and IMHO some of them are too complicated to use (I would prefer handcoding the HTML instead of using HTMLWriter).
I'll see about researching into these myself in the meantime.  I am currently debating on using Pascal for future web projects, especially where performance might be needed.  When comparing how fast a page loads in Pascal to dynamic languages like Python, it really shows a speed boast, as there's no more bytecode VM in the middle.  I'd personally like to do a basic benchmark to say compare fpWeb with a Python microframework like Bottle.py.
Good luck. My company has one (I injected it when the others are unconscious), just a simple SQLite backed web services + front end pages. Actually I use it for benchmarking SQLite, since the Pascal part is already blazing fast while requiring only a small amount of RAM (the biggest use is SynMustache because it caches the templates).
Title: Re: [Tutorial] Basic fpWeb Tutorial Article
Post by: kveroneau on February 02, 2016, 01:44:08 am
Thank you for your swift reply, that's good to know that the other module types can make things a bit more complicated, I'll hold off on looking at them for now.  I guess the session stuff is pretty much down packed, is there a way to customize the session cookie name?  Say, you have 2 fpWeb apps on a single domain, but want each to keep a separate session.  Where are the session INI files kept?  Are they placed in /tmp, or in the directory where your application was started?  Can the location of the session INIs be easily customized?

As for the status codes, 302 is a redirect, and I believe I may have found out how to send one: AResponse.SendRedirect appears to get the job done.  In modern web apps, after say adding an object using a form, the page which was just POST'd to, usually performs a redirect back to either a form to edit the object just added, or redirects to the object list page.
Title: Re: [Tutorial] Basic fpWeb Tutorial Article
Post by: bee on February 02, 2016, 05:31:26 am
If you know the basic mechanisms of how a web app works, actually you don't need fpWeb to write a web app using Pascal. I've been making many web apps using Pascal since about 10 years ago, long before fpWeb existed. HTTP is a pretty old technology, you know. :)

IMHO, it's not about the future of Pascal for web because it has been able to do that since the beginning. I remember my first Pascal web app was written using Turbo Pascal 7.0. Basically it's just about how to read from stdin and to write to stdout using HTTP communication protocol. It's long before PHP even existed.

It's more about how we use Pascal to compete with currently over-hype web tools/frameworks/languages. Object Pascal is an advance language since its inception. It's just born too early so most people don't understand its capability.
Title: Re: [Tutorial] Basic fpWeb Tutorial Article
Post by: edwinyzh on March 16, 2016, 08:09:53 am
Well done and Thanks! Downloaded :)
Title: Re: [Tutorial] Basic fpWeb Tutorial Article
Post by: JD on March 24, 2016, 10:22:17 am
If you know the basic mechanisms of how a web app works, actually you don't need fpWeb to write a web app using Pascal. I've been making many web apps using Pascal since about 10 years ago, long before fpWeb existed. HTTP is a pretty old technology, you know. :)

IMHO, it's not about the future of Pascal for web because it has been able to do that since the beginning. I remember my first Pascal web app was written using Turbo Pascal 7.0. Basically it's just about how to read from stdin and to write to stdout using HTTP communication protocol. It's long before PHP even existed.

It's more about how we use Pascal to compete with currently over-hype web tools/frameworks/languages. Object Pascal is an advance language since its inception. It's just born too early so most people don't understand its capability.

Well said & every encouraging. Thanks to Leledumbo for his excellent work. I never understood how fpWeb worked beforehand but I'll now give it a try.

JD
Title: Re: [Tutorial] Basic fpWeb Tutorial Article
Post by: Leledumbo on March 24, 2016, 07:02:24 pm
Well said & every encouraging. Thanks to Leledumbo for his excellent work. I never understood how fpWeb worked beforehand but I'll now give it a try.
Don't worry, I can guarantee 1 out of 10 web developers don't actually understand how browsers and servers communicate, HTTP protocol or even basic networking works ;)
So if you give it a try, at least you're already one step ahead.
Title: Re: [Tutorial] Basic fpWeb Tutorial Article
Post by: aradeonas on March 24, 2016, 07:43:28 pm
@Leledumbo, it seems you are active in web development and I saw some your activities about this like your posts in your blog (I like to read more but you didnt update it lately) so I want to ask is it good doing web stuff with fpc? what libraries do you used? did you tried Brook,didi you liked it?
What fields in web you think fpc is more usefull?
Beside this post what sources should I read for this subject?
Title: Re: [Tutorial] Basic fpWeb Tutorial Article
Post by: Leledumbo on March 25, 2016, 09:33:21 am
so I want to ask is it good doing web stuff with fpc?
You should've figured it out yourself. Why the hell do I keep posting it if it's not good? ;)
what libraries do you used? did you tried Brook,didi you liked it?
Brook, exactly. fpWeb is secondary choice.
What fields in web you think fpc is more usefull?
Everything, no exception.
Beside this post what sources should I read for this subject?
General knowledge about networking, HTTP protocol, specific web server configuration, AJAX, JSON, etc. Too many to list if you have no clear goal.
Title: Re: [Tutorial] Basic fpWeb Tutorial Article
Post by: marcov on March 25, 2016, 10:09:23 am
I actually ported FPC to FreeBSD in 1999-2000 because I wanted to run cgis on my FreeBSD account. It was my first major job as FPC devel.

The CGIs were a kind of webcounters btw.
Title: Re: [Tutorial] Basic fpWeb Tutorial Article
Post by: aradeonas on March 25, 2016, 12:10:12 pm
Thanks @Leledumbo.
Mostly I like to make some API for my programs to work with so avoid writing PHP for my API parts. I never saw a easy to learn demo for making an API system with authentication.
Title: Re: [Tutorial] Basic fpWeb Tutorial Article
Post by: Leledumbo on March 25, 2016, 04:31:25 pm
Thanks @Leledumbo.
Mostly I like to make some API for my programs to work with so avoid writing PHP for my API parts. I never saw a easy to learn demo for making an API system with authentication.
Because it's no different from normal HTTP request/response flow, just specially dictated (what you have to send, what you will receive) in some parsable text (json, xml, whatever). It's a matter of knowledge combining, although in PHP world it's often overrated by being something special and thus require special libraries as well.
Title: Re: [Tutorial] Basic fpWeb Tutorial Article
Post by: aradeonas on March 25, 2016, 04:39:55 pm
Quote
Because it's no different from normal HTTP request/response flow, just specially dictated (what you have to send, what you will receive) in some parsable text (json, xml, whatever). It's a matter of knowledge combining, although in PHP world it's often overrated by being something special and thus require special libraries as well.
But it good to have one example for beginners anyway.
Title: Re: [Tutorial] Basic fpWeb Tutorial Article
Post by: Leledumbo on March 25, 2016, 05:37:28 pm
But it good to have one example for beginners anyway.
I don't consider web service API with authentication as a beginner task, which is why I don't write one for it. I always write basic tutorial and only advanced ones if they're not merely a knowledge combining, for instance: compiler construction. I assume knowledge combining to be basic requirement for intermediate programmers, in fact that's what makes them different from beginners.

Below is a simple echo API with basic access authentication using Brook:
Code: Pascal  [Select][+][-]
  1. program SimpleAPIWithBasicAuthentication;
  2.  
  3. {$mode objfpc}{$H+}
  4. {$define debug}
  5.  
  6. uses
  7.   base64,
  8.   fpjson,
  9.   httpprotocol,
  10.   BrookUtils,
  11.   BrookLogger,
  12.   BrookAction,
  13.   BrookHttpDefs,
  14.   BrookFCLHTTPAppBroker,
  15.   BrookApplication;
  16.  
  17. const
  18.   ValidUsername = 'root';
  19.   ValidPassword = 'admin';
  20.  
  21. type
  22.  
  23.   { TAPIAction }
  24.  
  25.   TAPIAction = class(TBrookAction)
  26.   protected
  27.     FJSONResponse: TJSONObject;
  28.   public
  29.     procedure DoRequest(ARequest: TBrookRequest; AResponse: TBrookResponse); override;
  30.   end;
  31.  
  32.   { TAuthenticatedAction }
  33.  
  34.   TAuthenticatedAction = class(TAPIAction)
  35.   private
  36.     function IsValidToken(const AToken: String): Boolean;
  37.   public
  38.     procedure Request(ARequest: TBrookRequest; AResponse: TBrookResponse); override;
  39.   end;
  40.  
  41.   { TEchoAction }
  42.  
  43.   TEchoAction = class(TAuthenticatedAction)
  44.     procedure Get; override;
  45.   end;
  46.  
  47. { TAPIAction }
  48.  
  49. procedure TAPIAction.DoRequest(ARequest: TBrookRequest;
  50.   AResponse: TBrookResponse);
  51. var
  52.   Log: String;
  53. begin
  54.   FJSONResponse := TJSONObject.Create;
  55.   try
  56.     inherited DoRequest(ARequest, AResponse);
  57.     // Every output is considered a log
  58.     Log := AResponse.Content;
  59.     if (Length(Log) > 0) and BrookSettings.LogActive then begin
  60.       TBrookLogger.Service.Info(Log);
  61.     end;
  62.     // Override content by JSON
  63.     AResponse.Content := FJSONResponse.{$ifndef debug}AsJSON{$else}FormatJSON{$endif};
  64.   finally
  65.     FJSONResponse.Free;
  66.   end;
  67. end;
  68.  
  69. { TAuthenticatedAction }
  70.  
  71. function TAuthenticatedAction.IsValidToken(const AToken: String): Boolean;
  72. begin
  73.   Result := EncodeStringBase64(ValidUsername + ':' + ValidPassword) = AToken;
  74. end;
  75.  
  76. procedure TAuthenticatedAction.Request(ARequest: TBrookRequest; AResponse: TBrookResponse);
  77. var
  78.   AuthHeader, TokenPrefix, Token: String;
  79.   Authenticated: Boolean;
  80. begin
  81.   AuthHeader := ARequest.GetHeader(hhAuthorization);
  82.   // I love System.Copy's "no error" behavior :)
  83.   TokenPrefix := Copy(AuthHeader,1,6);
  84.   Token := Copy(AuthHeader,7,Length(AuthHeader));
  85.   Authenticated := (TokenPrefix = 'Basic ') and IsValidToken(Token);
  86.   if Authenticated then
  87.     inherited Request(ARequest, AResponse)
  88.   else begin
  89.     AResponse.Code := 401;
  90.     AResponse.CodeText := 'Unauthorized';
  91.     AResponse.SetHeader(hhWWWAuthenticate,'Basic realm="API"');
  92.     FJSONResponse.Add('status',AResponse.Code);
  93.     FJSONResponse.Add('message',AResponse.CodeText);
  94.   end;
  95. end;
  96.  
  97. { TEchoAction }
  98.  
  99. procedure TEchoAction.Get;
  100. var
  101.   Msg: String;
  102. begin
  103.   Msg := HttpRequest.QueryFields.Values['message'];
  104.   if Length(Msg) > 0 then begin
  105.     FJSONResponse.Add('status',200);
  106.     FJSONResponse.Add('message',Msg);
  107.   end else begin
  108.     FJSONResponse.Add('status',400);
  109.     FJSONResponse.Add('message','Please provide "message" field');
  110.   end;
  111. end;
  112.  
  113. begin
  114.   TEchoAction.Register('/echo');
  115.   BrookSettings.Port := 4444;
  116.   BrookApp.Run;
  117. end.
  118.  
A beginner is likely to ask:
And many other non-essential things that may clutter a clean tutorial focusing on the web service itself. It's a self experience from teaching, and experiences don't lie ;)
Title: Re: [Tutorial] Basic fpWeb Tutorial Article
Post by: aradeonas on March 25, 2016, 09:02:43 pm
Thanks @Leledumbo. It is more clear for me know how to make a simple API.
Title: Re: [Tutorial] Basic fpWeb Tutorial Article
Post by: garlar27 on December 16, 2016, 04:51:26 pm
Thanks Leledumbo!
It's a good tutorial indeed!!

But I've got a doubt:
When building a module, is there a way to specify the for which Apache version (e.g. Apache 2.2 Apache 2.4) generate the module?
Title: Re: [Tutorial] Basic fpWeb Tutorial Article
Post by: Leledumbo on December 16, 2016, 06:36:08 pm
Thanks Leledumbo!
It's a good tutorial indeed!!

But I've got a doubt:
When building a module, is there a way to specify the for which Apache version (e.g. Apache 2.2 Apache 2.4) generate the module?
The unit names differ for both versions, look in your units folder.
Title: Re: [Tutorial] Basic fpWeb Tutorial Article
Post by: garlar27 on December 19, 2016, 02:33:34 pm
Thank you!!
The unit names differ for both versions, look in your units folder.
I've changed the units "httpd" to "httpd24" and "fpapache" to "fpapache24" now the apache server starts well. But when the request reaches the server it doesn't responds. Checking the apache "error_log" file I read that the error that occurred is

Quote
    An unhandled exception occurred at $00007FF8F0760C66:
    EHTTP: No REQUEST_METHOD passed from server.
      $00007FF8F0760C66
Googling the message "No REQUEST_METHOD passed from server" points to FPC repositories only. For that reason I added temporary logs everywhere to pin point if there is something wrong with my code (which works fine on Apache 2.2) and the only logs I have are the ones in the "begin ... end." of the ".lpr" file. It makes me think that the exception is raised before my code has a chance to read the request.

Is there any other thing I need to change? Maybe the ".fpc.cfg" file or any other unit?
Title: Re: [Tutorial] Basic fpWeb Tutorial Article
Post by: Leledumbo on December 21, 2016, 10:17:06 am
I've changed the units "httpd" to "httpd24" and "fpapache" to "fpapache24" now the apache server starts well. But when the request reaches the server it doesn't responds. Checking the apache "error_log" file I read that the error that occurred is

Quote
    An unhandled exception occurred at $00007FF8F0760C66:
    EHTTP: No REQUEST_METHOD passed from server.
      $00007FF8F0760C66
Googling the message "No REQUEST_METHOD passed from server" points to FPC repositories only. For that reason I added temporary logs everywhere to pin point if there is something wrong with my code (which works fine on Apache 2.2) and the only logs I have are the ones in the "begin ... end." of the ".lpr" file. It makes me think that the exception is raised before my code has a chance to read the request.
Something within apache virtual server config, I believe. I don't know how apache pass environment variables to its modules, but the core of fcl-web expects at least that environment variable to work.
Title: Re: [Tutorial] Basic fpWeb Tutorial Article
Post by: garlar27 on December 21, 2016, 06:03:09 pm
Well, things got more complicated than I anticipated. I will try to follow this problem in other thread.

Resume:
Changing the uses units "httpd" to "httpd24" and "fpapache" to "fpapache24" allow Apache server to start.

The problem I still have:
In case some one is interested will be explain in more detail in the following thread Problems with modules for APACHE 2.4 (http://forum.lazarus.freepascal.org/index.php/topic,35122.0.html)
Title: Re: [Tutorial] Basic fpWeb Tutorial Article
Post by: ozznixon on March 03, 2017, 05:17:11 pm
Kudos - Great Start!
Title: Re: [Tutorial] Basic fpWeb Tutorial Article
Post by: ahiggins on March 03, 2017, 05:25:16 pm
Thank you very much
Title: Re: [Tutorial] Basic fpWeb Tutorial Article
Post by: egsuh on March 24, 2017, 07:03:45 am
I cannot see the tutorial.  It says something like:  "Dropbox - 404 cannot the file".
Title: Re: [Tutorial] Basic fpWeb Tutorial Article
Post by: nummer8 on March 24, 2017, 08:54:18 am
Try this link

https://bitbucket.org/leledumbo/books/downloads/

or use google
fpweb tutorial

Jos
Title: Re: [Tutorial] Basic fpWeb Tutorial Article
Post by: egsuh on March 24, 2017, 10:11:55 am
Try this link

https://bitbucket.org/leledumbo/books/downloads/

or use google
fpweb tutorial

Jos

Thank you. Really appreciate.
Title: Re: [Tutorial] Basic fpWeb Tutorial Article
Post by: egsuh on March 24, 2017, 12:19:15 pm
I did some tests myself, and I'd like to share what I have found with you, hoping that my experience help some guys at least. I tried to make my own web-server application in CGI way. The structure is rather similar with "WEBSNAP" in Delphi, which is deprecated now.  What I'd like to say is about action of event handlers. 

I put one module, let's say "mod1", and one action, let's say "act1" and set it as default.

If you call your app from browser, by typing in  "localhost/exec/mycgi.exe/act1" in the browser address windonw, it seems that event handlers run in following order:

- module_oncreate
- module_afterrequest
- module_beforerequest
- module_onrequest
- module_ongetaction

- action_beforerequest
- action_onrequest
- action_afterresponse

- module_afterresponse
- module_on destroy

This means you can process your data on the server side at any position here, except you set "handled := true" in moudle_onrequest procedure. This will make your application skip to "module_afterresponse".

Here, "processing" does not necessarily affect the HTML output, which client browser will actually see.  Basically you can change your output content directly, changing content of "AResponse.Contents" at module_onrequest, module_afterresponse, action_onrequest, action_afterresponse.

Let's see an example:

module_onrequest:
    AResponse.Contents.Add ('Hello, world <br />');
    Handled :=false;
action_onrequest:
   AResponse.Contents.Add('You called action <br />');
   Handled := true;     // if you comment this out, default serems handled = falset
action_afterresponse:
   AResponse.Contents.Add('Actions done<br />');
module_afterresponset:
    AResponse.Contents.Add ('I finished my response <br />');
 
Then you will see in our browser:

  Hello, world
  You called action
  Actions done
  I finished my response

If you set handled:=true in module_onrequest, then you would see:

  Hello, world

Setting "handled:= ture" does not operate in the same way in module and action. If you set handled true, the process in the module_afterresponse IS processed, but response contents defined there are not.

Another thing to mention is regarding defining "Contents" in action property --- you can directly type in the small editor box. Let's assume that you typed in "Contents from property Contents <br />" in Contents in act1's property. 

If you set handled := true in the action_onrequest, you will get the same result above (assuming handled := false in module_onrequest).

When you set handled to false in the action_onrequest, then you will get:
 
  Hello, world
  You called action
  Contents from property Contents
  Actions done
  I finished my response

With this, I think we can break down our application bit by bit, and process each part at different positions at our convenience.

Hope you can include this content in your tutorial if you think helpful. I spend rather long time to figure out this structure in the past, and want others who start webprogramming do not have to spend time here.
Title: Re: [Tutorial] Basic fpWeb Tutorial Article
Post by: Leledumbo on March 25, 2017, 07:19:39 am
Hope you can include this content in your tutorial if you think helpful. I spend rather long time to figure out this structure in the past, and want others who start webprogramming do not have to spend time here.
Feel free to submit a pull request. Although I'm a bit unsure whether such a deep flow explanation is necessary for basic tutorial. Moreover, recently it gets new simpler and a lot more flexible routing mechanism. I have no idea where to insert it in the existing sections.
Title: Re: [Tutorial] Basic fpWeb Tutorial Article
Post by: egsuh on March 26, 2017, 11:21:50 am
Feel free to submit a pull request. Although I'm a bit unsure whether such a deep flow explanation is necessary for basic tutorial. Moreover, recently it gets new simpler and a lot more flexible routing mechanism. I have no idea where to insert it in the existing sections.

You are right. there are many other ways of routing. This may be useful only when setting "handled" is the most convenient way of controlling  flow. I just wanted to make it easier to understand the role of setting 'handled" true or false.
Title: Re: [Tutorial] Basic fpWeb Tutorial Article
Post by: juliano on May 26, 2017, 03:06:50 am
Hello Leledumbo, do you have any brook framework tutorial?
Title: Re: [Tutorial] Basic fpWeb Tutorial Article
Post by: Leledumbo on May 26, 2017, 07:00:37 am
Hello Leledumbo, do you have any brook framework tutorial?
In my head, not yet dumped to books.
Title: Re: [Tutorial] Basic fpWeb Tutorial Article
Post by: valdir.marcos on May 26, 2017, 11:21:33 am
Hello Leledumbo, do you have any brook framework tutorial?

Have you already looked at these links?
http://wiki.freepascal.org/Brook_Framework
http://silvioprog.github.io/brookframework/
https://brookframework.org/
Brook,JSON,MySQL
http://forum.lazarus.freepascal.org/index.php?topic=24668.0
[OT] Nice post about Brook framework
http://forum.lazarus.freepascal.org/index.php?topic=19406.0
http://pascalgeek.blogspot.com.br/2012/12/brook-framework-new-web-application.html
https://github.com/silvioprog
[ANN] Travel Lazarus Brook | REST | JSON
http://forum.lazarus-ide.org/index.php/topic,24018.msg144196.html#msg144196
Title: Re: [Tutorial] Basic fpWeb Tutorial Article
Post by: Leledumbo on June 03, 2018, 11:14:13 pm
My tutorial has been updated tocover the new routing mechanism. The PDF has been generated from Typora instead of ReText and internal links are now working. To avoid confusion, old downloads have been removed.
Title: Re: [Tutorial] Basic fpWeb Tutorial Article
Post by: egsuh on June 08, 2018, 05:18:56 am
Wow really great. Really appreciate your efforts. Downloading from dropbox does not work.
So I downloaded from

https://bitbucket.org/leledumbo/books/downloads/
Title: Re: [Tutorial] Basic fpWeb Tutorial Article
Post by: af0815 on June 08, 2018, 07:03:21 am
The tutorial is very inetresting. Thanks for sharing the information
Title: Re: [Tutorial] Basic fpWeb Tutorial Article
Post by: Leledumbo on June 08, 2018, 07:01:25 pm
The addition of new routing mechanism didn't take the whole article into considerations. Therefore, you might find the routing section a bit detached from the others. I'm thinking on better restructuring, supporting the two mechanism without duplicating the effort in other sections. Right now, other sections are written with the old mechanism in mind. Feel free to state any idea for this.
Title: Re: [Tutorial] Basic fpWeb Tutorial Article
Post by: nummer8 on June 08, 2018, 07:09:55 pm
Thank you for adding the routing part!

Jos
Title: Re: [Tutorial] Basic fpWeb Tutorial Article
Post by: GAN on June 08, 2018, 10:16:42 pm
Hello Leledumbo, what is the license of the tutorial?

Best regards.
Title: Re: [Tutorial] Basic fpWeb Tutorial Article
Post by: Leledumbo on June 09, 2018, 10:58:46 am
Hello Leledumbo, what is the license of the tutorial?

Best regards.
Damn right, I never state it. I'll probably make it CC BY-SA, as I want modifications to be contributed back.
Title: Re: [Tutorial] Basic fpWeb Tutorial Article
Post by: BSaidus on January 28, 2023, 08:25:42 pm
Hi @Leledumbo
I can not find the pdf, Can you make it online back.
Thanks.
Title: Re: [Tutorial] Basic fpWeb Tutorial Article
Post by: dseligo on January 28, 2023, 10:29:35 pm
Hi @Leledumbo
I can not find the pdf, Can you make it online back.
Thanks.

Not PDF, but wiki: https://wiki.lazarus.freepascal.org/fpWeb_Tutorial (https://wiki.lazarus.freepascal.org/fpWeb_Tutorial)
Title: Re: [Tutorial] Basic fpWeb Tutorial Article
Post by: egsuh on January 28, 2023, 11:20:32 pm
Thank you for your hard working.  Following is an excerpt from the tutorial.
 
Shouldn't parameters    AResponse   be defined as    AResponse:TResponse,   in TRouteCallback and TRouteEvent?


Quote
Registering a Route

The 2nd, 3rd or 4th parameter (depending on whether you want to handle specific HTTP method and/or pass additional data to it) of HTTPRouter.RegisterRoute is overloaded with several possibilities:

    Callback procedure

TRouteCallback = Procedure(ARequest: TRequest; AResponse);

    Callback event

TRouteEvent = Procedure(ARequest: TRequest; AResponse) of object;
Title: Re: [Tutorial] Basic fpWeb Tutorial Article
Post by: Leledumbo on February 02, 2023, 10:31:25 am
Hi @Leledumbo
I can not find the pdf, Can you make it online back.
Thanks.
Sorry, I quitted using dropbox. The book is now on github (https://github.com/leledumbo/fpWebTutorial), feel free to clone and generate the PDF yourself.
Title: Re: [Tutorial] Basic fpWeb Tutorial Article
Post by: Roland57 on February 02, 2023, 10:53:59 am
@leledumbo

Thank you for sharing.

For me, I have zero knowledge about web programming, and I don't have time nor need to learn it, but I am very interested in writing things in Markdown. Please could you share your method for generating HTML and PDF documents? Do you use pandoc, or another tool?

Regards.

Roland
Title: Re: [Tutorial] Basic fpWeb Tutorial Article
Post by: Leledumbo on February 02, 2023, 09:45:03 pm
Please could you share your method for generating HTML and PDF documents? Do you use pandoc, or another tool?
The editor I use is Typora, it indeed depends on pandoc to generate its export formats, but I don't need to see that, it's a single menu item from the editor.
Title: Re: [Tutorial] Basic fpWeb Tutorial Article
Post by: dbannon on February 02, 2023, 11:41:28 pm
Wow, you have done a lot of work to get that on Github, well done !

If the content still the same as that on the Wiki or have you updated it as you go ?

(just wondering if there should be a link to the github page from the wiki and visa versa)

Davo

Title: Re: [Tutorial] Basic fpWeb Tutorial Article
Post by: Leledumbo on February 02, 2023, 11:45:58 pm
If the content still the same as that on the Wiki or have you updated it as you go ?
Guess it's still the same, I don't really remember. Just diff it out yourself. Was a mistake putting it on bitbucket, I've lost all the history and left with latest available locally.
Title: Re: [Tutorial] Basic fpWeb Tutorial Article
Post by: Roland57 on February 03, 2023, 05:45:36 am
The editor I use is Typora, it indeed depends on pandoc to generate its export formats, but I don't need to see that, it's a single menu item from the editor.

Thanks for your answer. I will take a look to Typora.
Title: Re: [Tutorial] Basic fpWeb Tutorial Article
Post by: PierceNg on February 03, 2023, 07:04:39 am
Thanks for your answer. I will take a look to Typora.

You might be interested in https://github.com/grahamegrieve/delphi-markdown which works with FPC.

Markdown processors usually generate HTML fragments, so Markdown is usually combined with a template system such as Mustache to generate complete HTML documents. FPC comes with a Mustache processor in package fcl-mustache in its main branch.
Title: Re: [Tutorial] Basic fpWeb Tutorial Article
Post by: Roland57 on February 03, 2023, 07:43:21 am
@PierceNg

Very interesting indeed. I will look at it. Thanks!
TinyPortal © 2005-2018