Forum > Networking and Web Programming

[Tutorial] Basic fpWeb Tutorial Article

<< < (3/13) > >>

cappe:
Thank you

tigerA15:
that's great.

kveroneau:
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:

--- Quote from: kveroneau on February 02, 2016, 12:26:44 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?

--- End quote ---
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.

--- Quote from: kveroneau on February 02, 2016, 12:26:44 am --- * 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.

--- End quote ---
Hmm... I did mention the dialog but doesn't go deep enough of how it works. Noted.

--- Quote from: kveroneau on February 02, 2016, 12:26:44 am --- * How could you override the default request handler?  Currently the URI system is /module/action, with no mentioning of any customization.

--- End quote ---
Application.OnGetModule should be exploited.

--- Quote from: kveroneau on February 02, 2016, 12:26:44 am --- * How can you send out another HTTP response code?  Such as 403, or a 302 to the browser?

--- End quote ---
I missed that one. Noted. In the meantime, try setting Response.Code.

--- Quote from: kveroneau on February 02, 2016, 12:26:44 am --- * An example of how to override Application.OnGetModule would be great!

--- End quote ---
I consider custom routing as not "basic", let me think about it.

--- Quote from: kveroneau on February 02, 2016, 12:26:44 am --- * How to handle exceptions in production, such as sending out an email to the admin with the exception text.

--- End quote ---
This should be out of the tutorial since the custom exception handling has been covered and email sending is not part of fpWeb feature.

--- Quote from: kveroneau on February 02, 2016, 12:26:44 am --- * Can the exceptions during development be set to be more human to read?  Currently, the stack trace reads like machine code.

--- End quote ---
Again, back to tips and tricks on custom exception handler.

--- Quote from: kveroneau on February 02, 2016, 12:26:44 am --- * More example code on using sessions, and how the browser cookie is set for these sessions.

--- End quote ---
More? What's missing? How the browser cookie is set could be added, it's just informational (see FPWebSession in your browser's cookie).

--- Quote from: kveroneau on February 02, 2016, 12:26:44 am --- * Examples on how to use the other lazweb module types: Web DataProvider, Web JSON-RPC, Web Ext.Direct, HTML Web

--- End quote ---
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).

--- Quote from: kveroneau on February 02, 2016, 12:26:44 am ---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.

--- End quote ---
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:
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.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version