Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2019-03

Web Server Written in Free Pascal?

7 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Anthony Walter

I've been tutoring kids on programming and using Free Pascal as their first computer language. I've been creating example programs to demonstrate different things computer can do and how certain technologies.

In that endeavor I've written a basic multi threaded web server as a command line application. I wanted to know if other people have done this much and it would be worthwhile for me to write up a small page with some example extensions to the web server. What is your opinion, are of this type of web server implementation and if there would be any value dedicating some time to writing up a page about it with more information.

The basic web server program which you can extend looks like this (optional clii switches include -port and binding -address):

{ A simple web server application }
program WebServer;
{$mode delphi}
uses
  WebServer.Tools;
{ This is our web handler for the web server }
procedure WebHandler(Request: TWebRequest; Response: TWebResponse);
begin
  { Try to send the requested resource }
  if not Response.SendFile(Request.Path) then
  begin
    { If it's not found return a 404 page }
    Response.Status := 404;
      Response.SendFile('/404');
  end;
  { Optionally print the request }
  if OptionVerbose then
      Request.Print;
end;
begin
  { Run the web server }
  WebServerRun(WebHandler);
end.

And objects to work upon the customizing your server look like this:

{ The TWebRequest class represents an http request }
type
  TWebRequest = class
  private
    procedure Parse(const Request: string);
  public
    { The raw request text sent by the client web browser }
    Raw: string;
    { Method which is usually GET or POST }
    Verb: string;
    { Path to the resource requested }
    Path: string;
    { Optional raw query string }
    Query: string;
    { Header name value pairs parsed into a handy collection }
    Headers: TNamedStrings;
    { Query or form parameter name value pairs parsed into a handy
collection }
    Params: TNamedStrings;
    { Print out all the information related to the request }
    procedure Print;
  end;

Reply by email

Michael Van Canneyt
to Anthony Walter
Anthony Walter wrote 14 lines
I've been tutoring kids on programming and using Free Pascal as their first computer language. I've been creating example programs to demonstrate different things computer can do and how certain technologies. In that endeavor I've written a basic multi threaded web server as a command line application. I wanted to know if other people have done this much and it would be worthwhile for me to write up a small page with some example extensions to the web server. What is your opinion, are of this type of web server implementation and if there would be any value dedicating some time to writing up a page about it with more information. The basic web server program which you can extend looks like this (optional clii switches include -port and binding -address):

Ehm.
Have you ever checked out fpWeb ? This exists since many years, distributed by default in FPC. The trunk version even supports SSL.

Michael.

Reply by email

Michael Van Canneyt
to Anthony Walter
Anthony Walter wrote
No I haven't. I will check it out thank you. I just thought my implementation and interface was rather clean, simple, and easy to understand.

I hope you'll be pleasantly surprised by the multitude of webprogramming tools available in FPC. This is an area of very active development, the latest addition is a complete REST bridge for SQLDB.

You may also want to check out the brook framework by Silvio Clecio and WST if you need to create webservices.

Michael.

Reply by email

Dennis
to Michael Van Canneyt: I hope you'll be pleasantly surprised by the multitude of webprogramming tools available…
Michael Van Canneyt wrote 12 lines
On Wed, 27 Mar 2019, Anthony Walter wrote: > No I haven't. I will check it out thank you. I just thought my > implementation and interface was rather clean, simple, and easy to > understand. I hope you'll be pleasantly surprised by the multitude of webprogramming tools available in FPC. This is an area of very active development, the latest addition is a complete REST bridge for SQLDB.

Can you share the link of REST bridge for SQLDB?

Dennis

Reply by email

Michael Van Canneyt
to Dennis
Dennis wrote 17 lines
Michael Van Canneyt wrote: > > > On Wed, 27 Mar 2019, Anthony Walter wrote: > >> No I haven't. I will check it out thank you. I just thought my >> implementation and interface was rather clean, simple, and easy to >> understand. > > I hope you'll be pleasantly surprised by the multitude of webprogramming > tools available in FPC. This is an area of very active development, the > latest addition is a complete REST bridge for SQLDB. > Can you share the link of REST bridge for SQLDB?

Sure:

http://wiki.freepascal.org/SQLDBRestBridge

Today I made an integration with TMS Web core, so you can access it even from Delphi in multiple ways :)

Michael.

Reply by email