[Lazarus] Lazarus/FPC for Web Development only

silvioprog silvioprog at gmail.com
Sat Feb 22 23:02:37 CET 2014


2014-02-22 15:11 GMT-03:00 Giuseppe Luigi <glpunzi at gmail.com>:

> Sorry for late reply, too busy :(
>
> What approach you follow to build your sites? Jtemplate? Use brook just as
> restful server?
>
I use it according the project. In several projects, I use only GET/POST,
JTemplate and HTML. But there are also projects that I use
GET/POST/PUT/DELETE, RESTful and some JS library, such as JTable, for
example.

> Im still just trying to figure on my mind how to "deploy" my idea to Brook
> development. My web development skills are mainly based working over CMS
>
> Regards.
>
Some time ago, I have developed projects with CMS like Joomla and
WordPress. Yes, it is practical, but they don't give me the same power to
manipulate the content that will displayed on the screen. But I've thought
about creating a CMS using Brook.

ps. The Brook 3.0 is being released with new ideas of João Morais (
https://github.com/jcmoraisjr). It will be completely different from Brook
2.6.4. In the new Brook, you can receive objets instead JSONs, see a small
comparison;

form.html:

<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
 <title>Person</title>
</head>
<body>
<form action="http://localhost/cgi-bin/cgi1.bf" method="post">
 <input type="text" name="id" />
<input type="text" name="name" />
 <input type="submit" />
</form>
</body>
</html>

Brook 2.6.4:

unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  BrookAction;

type
  TMyAction = class(TBrookAction)
  public
    procedure Post; override;
  end;

implementation

procedure TMyAction.Post;
begin
  // where's validation?
  Write('ID: %d, Name: %s', [Fields['id'].AsInt64,
Fields['name'].AsString]); // where's reuse?
  // where's persistence?
end;

initialization
  TMyAction.Register('/person');

end.

Brook 3.0:

unit person;

{$mode objfpc}{$H+}

interface

uses
  SysUtils;

type
  EPerson = class(Exception);

  { TPerson }

  TPerson = class
  private
    FId: Int64;
    FName: string;
  public
    procedure Validate;
    procedure Save;
  published
    property Id: Int64 read FId write FId;
    property Name: string read FName write FName;
  end;

implementation

{ TPerson }

procedure TPerson.Validate;
begin
  if Trim(FName) = '' then
    raise EPerson.Create('Name must not be empty.');
end;

procedure TPerson.Save;
begin
  // implement your persistence here, using a framework like dpof:
https://github.com/silvioprog/dopf
end;

end.

unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  BrookAction, person;

type
  TMyAction = class(specialize TBrookEntityAction<TPerson>)
  public
    procedure Post; override;
  end;

implementation

procedure TMyAction.Post;
begin
  Entity.Validate; // Yes, my own validation!
  Write('ID: %d, Name: %s', [Entity.Id, Entity.Name]); // Yes, I'm reusing
my object!
  Entity.Save; // I love it, my validation using OPF (like
https://github.com/jcmoraisjr/jcore or https://github.com/silvioprog/dopf)
of DAO!
end;

initialization
  TMyAction.Register('/person');

end.

-- 
Silvio Clécio
My public projects - github.com/silvioprog
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20140222/cc0dcf6d/attachment-0003.html>


More information about the Lazarus mailing list