Author Topic: fphttpserver and httprouter  (Read 387 times)


  • New Member
  • *
  • Posts: 13
fphttpserver and httprouter
« on: August 22, 2020, 02:50:24 am »
Hello everyone, i was just wondering if it is possible to use fphttpserver with httprouter? I don not want to use fphttpapp, i want to create a fphttpserver object and have it somehow use httprouter. When i use fphttpapp and httprouter, it works. But when i make a fphttpserver object and use httprouter to register routes, it doesn't work.
Code: Pascal  [Select][+][-]
  1. program Project1;
  2. uses
  3.     fphttpserver,httpdefs,httproute;
  5. Procedure hi(ARequest: TRequest; AResponse: TResponse);
  6. begin
  7.   AResponse.Contents.Add('<h1>hi!</h1>');
  8. end;
  10. var
  11.   httpsrv:TFPHttpServer;
  12. begin
  13.   httpsrv:=TFPHttpServer.Create(nil);
  14.   httpsrv.Active:=false;
  15.   httpsrv.Port:=8080;
  16.   HTTPRouter.RegisterRoute('/',@hi);
  17.   httpsrv.Active:=true;
  18.   readln;
  19. end.

When i run this code, it doesn't give the "Hi!" i am looking for, just a blank web page.


  • Hero Member
  • *****
  • Posts: 8273
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: fphttpserver and httprouter
« Reply #1 on: August 22, 2020, 09:14:38 am »
You can't just do this. fphttpserver has no idea about httproute at all, they're not connected directly. It's custweb that knows httproute, and the various cust* (alongside end user fp*) units implement custweb interfaces of application, handler, request and response so they implicitly uses httproute. If you don't like any of those, you have to do the same in order to use httproute functionality. Or, explicitly uses HTTPRouter object in your OnRequest handler.


  • New Member
  • *
  • Posts: 13
Re: fphttpserver and httprouter
« Reply #2 on: August 23, 2020, 02:49:16 am »
Thank you for your reply. This makes alot sense! I had thought that the interface to httproute was on the fphttpserver level and that fphttpapp was just a nice application wrapper for fphttpserver. Now i understand alot better!


TinyPortal © 2005-2018