* * *

Author Topic: [Tutorial] Basic fpWeb Tutorial Article  (Read 13519 times)

Leledumbo

  • Hero Member
  • *****
  • Posts: 7651
  • Programming + Glam Metal + Tae Kwon Do = Me
[Tutorial] Basic fpWeb Tutorial Article
« on: July 14, 2015, 01:13:40 pm »
I proudly present my latest writing: Basic fpWeb Tutorial.
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 ;)

bee

  • Sr. Member
  • ****
  • Posts: 283
Re: [Tutorial] Basic fpWeb Tutorial Article
« Reply #1 on: July 15, 2015, 05:17:51 am »
Great job, bro. Thank you. With just one suggestion... provide example(s). :)
-Bee-

A long time pascal lover.

motaz

  • Sr. Member
  • ****
  • Posts: 497
    • http://code.sd
Re: [Tutorial] Basic fpWeb Tutorial Article
« Reply #2 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

exdatis

  • Hero Member
  • *****
  • Posts: 662
    • exdatis
Re: [Tutorial] Basic fpWeb Tutorial Article
« Reply #3 on: July 15, 2015, 10:12:52 am »
Thank you very much!

nomorelogic

  • Full Member
  • ***
  • Posts: 108
Re: [Tutorial] Basic fpWeb Tutorial Article
« Reply #4 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

Trenatos

  • Full Member
  • ***
  • Posts: 228
Re: [Tutorial] Basic fpWeb Tutorial Article
« Reply #5 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.

Trenatos

  • Full Member
  • ***
  • Posts: 228
Re: [Tutorial] Basic fpWeb Tutorial Article
« Reply #6 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

Leledumbo

  • Hero Member
  • *****
  • Posts: 7651
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: [Tutorial] Basic fpWeb Tutorial Article
« Reply #7 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.

eny

  • Hero Member
  • *****
  • Posts: 1561
Re: [Tutorial] Basic fpWeb Tutorial Article
« Reply #8 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).
All posts based on: Win10 (Win64); Lazarus 1.4.2 'stable' (#49524 win32) unless specified otherwise...

Trenatos

  • Full Member
  • ***
  • Posts: 228
Re: [Tutorial] Basic fpWeb Tutorial Article
« Reply #9 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.

cappe

  • New member
  • *
  • Posts: 45
Re: [Tutorial] Basic fpWeb Tutorial Article
« Reply #10 on: November 19, 2015, 05:55:33 pm »
Thank you

tigerA15

  • New member
  • *
  • Posts: 17
Re: [Tutorial] Basic fpWeb Tutorial Article
« Reply #11 on: November 30, 2015, 05:12:02 am »
that's great.

kveroneau

  • New member
  • *
  • Posts: 33
Re: [Tutorial] Basic fpWeb Tutorial Article
« Reply #12 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.

Leledumbo

  • Hero Member
  • *****
  • Posts: 7651
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: [Tutorial] Basic fpWeb Tutorial Article
« Reply #13 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).

kveroneau

  • New member
  • *
  • Posts: 33
Re: [Tutorial] Basic fpWeb Tutorial Article
« Reply #14 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.

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus