Hm, actually, I ran into a problem.Please be specific, I'm not an oracle. I can't see what you code, how you run it, etc.
After creating a new application, and trying to start it as described, I get an error when I visit the page: TCustomHTTPModule not found
Hm, actually, I ran into a problem.Please be specific, I'm not an oracle. I can't see what you code, how you run it, etc.
After creating a new application, and trying to start it as described, I get an error when I visit the page: TCustomHTTPModule not found
* 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 WebDefinitely 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).
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.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 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.
Thanks @Leledumbo.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.
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.But it good to have one example for beginners anyway.
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.
Thanks Leledumbo!The unit names differ for both versions, look in your units folder.
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.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
An unhandled exception occurred at $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.
EHTTP: No REQUEST_METHOD passed from server.
$00007FF8F0760C66
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 isSomething 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.QuoteAn unhandled exception occurred at $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.
EHTTP: No REQUEST_METHOD passed from server.
$00007FF8F0760C66
Try this link
https://bitbucket.org/leledumbo/books/downloads/
or use google
fpweb tutorial
Jos
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.
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.
Hello Leledumbo, do you have any brook framework tutorial?In my head, not yet dumped to books.
Hello Leledumbo, do you have any brook framework tutorial?
Hello Leledumbo, what is the license of the tutorial?Damn right, I never state it. I'll probably make it CC BY-SA, as I want modifications to be contributed back.
Best regards.
Hi @Leledumbo
I can not find the pdf, Can you make it online back.
Thanks.
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;
Hi @LeledumboSorry, I quitted using dropbox. The book is now on github (https://github.com/leledumbo/fpWebTutorial), feel free to clone and generate the PDF yourself.
I can not find the pdf, Can you make it online back.
Thanks.
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.
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.
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.