summaryrefslogtreecommitdiff
path: root/fpcsrc/packages/fcl-web/src/webdata/readme.txt
blob: 8766b1d5546b28ff7924e025a09046d88c512537 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
FPC WebData architecture
========================

The aim of this set of components is to be able to easily send data 
to a webapplication, and to handle updates of this data, all in a
webserver module.

The following components are used

- TFPWebDataProvider
  The central component, forming a bridge between TDataset and web content.

- TCustomWebdataInputAdaptor
    A class that transforms the input of a web request to something that
    TFPWebDataProvider understands. Example implementations are provided 
    for ExtJS, XML and JSON.

- TWebdataInputAdaptor
   A descendent of TCustomWebdataInputAdaptor that allows to select the
   input format from a list of known formats.

- TCustomHTTPDataContentProducer
    This class produces the response for the webapplication. It is an
    abstract class: descendents need to be made for the various expected
    outputs. Example implementations are provided for ExtJS, XML and JSON.

- THTTPDataContentProducer
   A descendent of TCustomHTTPDataContentProducer that allows to select the
   output format from a list of known formats.

- TFPWebProviderDataModule
   A THTTPSessionDatamodule descendent that can be used to handle data
   requests from a webclient. It functions as a container for
   TFPWebDataProvider components, InputAdaptors and Content producers.

   A module is registered in the Lazarus IDE package under File/New.

Typically, one will do the following
 - Create a TFPWebProviderDataModule from the IDE.
 - Drop some dataset components on it, and set them up for use with some
   datasources
 - For each dataset, drop a TFPWebDataProvider component on the module, 
   and connect it to the datasource. The name of this component is exposed
   to the client.
 - Drop a suitable input adaptor.
 
The data can then typically be read through the URL:
baseurl/modulename/providername/read
Or updated through the URLs
baseurl/modulename/providername/update
baseurl/modulename/providername/create
baseurl/modulename/providername/delete
where baseurl is the base URL for the web-application.

Large applications: factory support
For large-scale applications with lots of different datasets, there is
support for registering dataproviders in a central factory system:

The WebDataProviderManager function returns an instance of
TFPWebDataProviderManager.

It must be used to register WebDataProvider names and classes:

Function RegisterProvider(Const AProviderName : String; AClass : TFPCustomWebDataProviderClass) : TWebDataProviderDef; overload;

The first form registers a class: an instance of this class will
be created by the factory whenever a provider of name AProviderName is
requested.

The TFPWebProviderDataModule class is aware of the WebDataProviderManager
factory class, and will look there for a TFPCustomWebDataProvider instance
if none is found in the webmodule instance itself and the
'UseProviderManager' property is 'True'.

The WebDataProviderManager factory can also Register a complete datamodule:

Procedure RegisterDatamodule(Const AClass : TDatamoduleClass);

This will register all WebDataProvider instances on the datamodule:
An instance will be created, all  TFPCustomWebDataProvider instances
will be registered with their component names. 
When a provider belonging to such a datamodule is requested, then
the module will be created, and the requested TFPCustomWebDataProvider 
instance is returned. 

A provider instance can be requested with the following factory methods:

Function GetProvider(Const ADef : TWebDataProviderDef; AOwner : TComponent;out AContainer : TComponent): TFPCustomWebDataProvider; 
Function GetProvider(Const AProviderName : String; AOwner : TComponent; Out AContainer : TComponent): TFPCustomWebDataProvider;

The result is the provider instance. All instances are created using a
container module: either this is the module class used in RegisterDatamodule
or a vanilla TDatamodule class. This instance is returned in AContainer.

The container must be freed by the caller.

In practise, this means that one creates a datamodule, drops some
TFPWebDataProvider instances on it, and adds the following call
to the initialization section of the unit:

WebDataProviderManager.RegisterDatamodule(TMyDataModule);

The TFPWebProviderDataModule that handles web requests will then be able
to handle requests for the TFPWebDataProvider instances on the datamodule.

Note that the RegisterDataModule routine will create an instance of the
datamodule to get a list of provider components (it uses the component.name
property). The WebDataProviderManager's 'registering' property will be set 
to true: this way one can avoid connecting to a database during registration.

The WebDataProviderManager also handles the registration of inputadataptors
and output contents producers.