This article has multiple issues. Please help improve it or discuss these issues on the talk page. (Learn how and when to remove these messages)
|
FCL-Web[1] is part of Free Pascal's Free Component Library (FCL), focusing on web (related) application development. The package helps users to develop CGI, FastCGI and embedded web server applications, as well as Apache modules. It provides units implementing HTTP(S) protocol and a somewhat low level web application framework, in the form of web modules. Some content producers (e.g. for automatic content generation from dataset) are also provided. Other prominent use is to send/retrieve data from/to web services (possibly using JSON-RPC).
Web Application Support Units
editfpcgi, fpfcgi, fphttpapp and fpapache[24] are the units implementing CGI, FastCGI, embedded web server and Apache module respectively. The interface between the units is made similar by utilizing object oriented inheritance. Therefore, a change of used unit in the uses clause is sufficient to create all 4 kinds of web applications, without code changes for most of the rest of the application. A notable exception might be the need to set port for FastCGI and embedded web server.
Other Units
edit- httpdefs unit defines base classes for cookies, sessions, file uploads, mime handling, HTTP header, request & response
- iniwebsession unit implements session management using .ini files
- fphttpserver unit provides ready to use multithreaded-able standalone http server
- fphttpclient unit provides class to send http requests and retrieve its responses. It implements all available HTTP 1.1 methods.\
- fphtml unit provides content producers
- fphttp unit provides abstract web framework support using web modules
- fpweb unit provides an implementation of fphttp's abstract web framework
fpWeb Framework
editfpWeb is a framework built on top of fcl-web units and itself is a part of fcl-web. The architecture is quite modular and a RAD package for use with Lazarus is available. A fpWeb application consists of one or more web modules, with optional one or more web actions for each module.
The framework uses static routing in the form of:
<base URL>/<module name>[/<action name>]
<module name>
is determined from the name given as argument to RegisterHTTPModule
call, while <action name>
is determined from the key in the action map of each module. As alternative, GET style routing is also supported:
<base URL>/?module=<module name>[&action=<action name>]
The string "module" and "action" can be configured through ModuleVariable
and ActionVar
, respectively.
Request handling is done in cascading manner using the following algorithm:
- Execute module's request handler (TFPWebModule.OnRequest)
- If the request is handled (TFPWebModule.OnRequest Handled parameter set to true), send the response
- Otherwise, delegate request handling to web actions
- Find web action corresponds to current request path, optionally use redirection/rewriting (TFPWebModule.OnGetAction)
- If found, execute the web action's request handler (TFPWebAction.OnRequest)
- If the request is handled (TFPWebAction.OnRequest Handled parameter set to true), send the response
- Otherwise, raise request not handled exception
- Otherwise, raise request not handled exception
References
editFurther reading
edit- Leonardo M. Ramé: Lazarus Server
- Leonardo M. Ramé: Web Programming with Object Pascal
- Michaël Van Canneyt: Lazarus for the web
- Michaël Van Canneyt: Creating a simple webserver in Lazarus
- Mario Ray Mahardhika: Basic fpWeb Tutorial