TMS Sparkle provides several components for design-time usage. The main purpose is to provide a RAD experience, by just dropping components in the form and configuring them, allowing setting up servers with almost no line of code.
Even though you can use the components at runtime, creating them from code, that would usually be not necessary, as the components are just wrappers for the existing non-component architecture.
As a general rule, you have server components, which inherit from TSparkleServer, that wrap server modules. Each server component must be associated to a dispatcher component (inherited from TSparkleDispatcher), which will handle the HTTP requests.
General usage is:
Drop a dispatcher component in the form (for example, TSparkeHttpSysDispatcher);
Drop a server component in the form (TSparkleStaticServer, TXDataServer, etc.);
Associated the server to the dispatcher through the Dispatcher property of server component;
Specify the BaseUrl property of the server (for example, http://+:2001/tms/myserver;
Configure any specific property of the server;
Set Active property of dispatcher component to true.
That would be enough. Run the application and your HTTP server will be running at the specified base url address. You can associated more than one server to the same dispatcher, as long as the servers as configured at different base url addresses.
|TSparkleStaticServer||TStaticModule - static file server.|
|TSparkleGenericServer||TAnonymousServerModule - a generic Sparkle server that handles raw requests.|
|TXDataServer||TXDataServerModule - the TMS XData server module.|
|TSparkleHttpSysDispatcher||THttpSysServer - It handles HTTP request using Windows http.sys (IIS-based) driver.
Provides methods Start, Stop and events OnStart, OnStop.
Server Components - Common Features
Server components wrap Sparkle server modules. There are several Sparkle server components, like TSparkleStaticServer, TSparkleGenericServer or even TXDataServer, but all of them inherit from the base TSparkleServer class and share the common features, available to all of them:
|BaseUrl: string||The root URL where the server will respond requests from. For example: "http://+:2001/tms/myserver".|
|Dispatcher: TSparkleDispatcher||The dispatcher component which will handle the HTTP communication and dispatch the requests to the server.|
|OnModuleCreate||The event will be fired when the server module instance is created by the component. Since every server component wraps a server module, in the end what the component does it create an instance of the module and pass it to the dispatcher. In this event you will have an opportunity to retrieve the server module instance and change/configure the way you want to.
The parameters of the event are Sender (the server component) and Module, which is the server module created.
Any server module can have middleware items added to it. You can directly add middleware to the server module (using the OnModuleCreate event, for example), but the server component already has a design-time middleware editor to make your life easier.
Right-click the component, and choose "Manage middleware list...".
This will open the design-time middleware editor where you can add different types of middleware available (CORS, Compress, JWT, etc.). Select the middleware from the list to see its properties in the object inspector and change it, if necessary.
The design-time middleware items added are just wrappers around the existing middleware classes, you can refer to the available middleware to learn about the properties available and what they are for.
TSparkleStaticServer component wraps the TStaticModule server module. The purpose is to server static files, as traditional HTTP server.
Besides the features that are common to all server components, TSparkleStaticServer provides the additional properties:
|RootDir: string||Contains the local directory from which the files will be served from. For example: "C:\mywebfiles".|
TSparkleGenericServer component wraps the TAnonymousServerModule server module. The purpose is to provide low-level processing to any HTTP request, using an event for that.
Besides the features that are common to all server components, this server provides the additional properties:
|OnProcessRequest: TProcessRequestEvent||This event is fired for each incoming HTTP request. Use the request object to read request data, and set the HTTP response using the response object.|