crudserver.dpr 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. (* _ _
  2. * | |__ _ __ ___ ___ | | __
  3. * | '_ \| '__/ _ \ / _ \| |/ /
  4. * | |_) | | | (_) | (_) | <
  5. * |_.__/|_| \___/ \___/|_|\_\
  6. *
  7. * Microframework which helps to develop web Pascal applications.
  8. *
  9. * Copyright (c) 2012-2021 Silvio Clecio <[email protected]>
  10. *
  11. * Brook framework is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU Lesser General Public
  13. * License as published by the Free Software Foundation; either
  14. * version 2.1 of the License, or (at your option) any later version.
  15. *
  16. * Brook framework is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  19. * Lesser General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Lesser General Public
  22. * License along with Brook framework; if not, write to the Free Software
  23. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  24. *)
  25. program crudserver;
  26. {$IFDEF MSWINDOWS}
  27. {$APPTYPE CONSOLE}
  28. {$ENDIF}
  29. uses
  30. BrookHTTPRequest,
  31. BrookHTTPResponse,
  32. BrookHTTPServer,
  33. Persistence;
  34. type
  35. THTTPServer = class(TBrookHTTPServer)
  36. protected
  37. procedure DoRequest(ASender: TObject; ARequest: TBrookHTTPRequest;
  38. AResponse: TBrookHTTPResponse); override;
  39. end;
  40. procedure THTTPServer.DoRequest(ASender: TObject; ARequest: TBrookHTTPRequest;
  41. AResponse: TBrookHTTPResponse);
  42. begin
  43. if ARequest.Payload.Length > 0 then
  44. SavePersons(ARequest.Payload.Content)
  45. else
  46. AResponse.SendStream(ListPersons, 200);
  47. end;
  48. begin
  49. with THTTPServer.Create(nil) do
  50. try
  51. Port := 8080;
  52. Open;
  53. if not Active then
  54. Exit;
  55. WriteLn('Server running at http://localhost:', Port);
  56. ReadLn;
  57. finally
  58. Free;
  59. end;
  60. end.