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

edit

fpcgi, 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

edit
 
fpWeb Architecture

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

  1. Execute module's request handler (TFPWebModule.OnRequest)
  2. If the request is handled (TFPWebModule.OnRequest Handled parameter set to true), send the response
  3. Otherwise, delegate request handling to web actions
    1. Find web action corresponds to current request path, optionally use redirection/rewriting (TFPWebModule.OnGetAction)
    2. If found, execute the web action's request handler (TFPWebAction.OnRequest)
      1. If the request is handled (TFPWebAction.OnRequest Handled parameter set to true), send the response
      2. Otherwise, raise request not handled exception
    3. Otherwise, raise request not handled exception

References

edit

Further reading

edit