program DemoWebServer;
{$mode objfpc}{$H+}
uses
  sysutils, fphttpapp, httpdefs, httproute, fpjson, opensslsockets;
procedure jsonResponse(var res : TResponse; data:String);
begin
  res.Content := data;
  res.Code := 200;
  res.ContentType := 'application/json';
  res.ContentLength:= length(res.Content);
  res.SendContent;
end;
procedure queryParamhandler(req: TRequest; res: TResponse);
var
  jObject : TJSONObject;
  aID : string;
begin
  try
    aID := req.QueryFields.Values['ID'];
    jObject := TJSONObject.Create;
    jObject.Strings['method'] := 'queryParamHandler';
    jObject.Strings['ID'] := aID;
    jsonResponse(res,jObject.AsJSON);
  finally
    jObject.Free;
  end;
end;
begin
  Application.Port := 9081;
  HTTPRouter.RegisterRoute('/Druckfreigabe', @queryParamHandler);
  Application.Threaded := true;
  Application.Initialize;
  Writeln(format('DemoWebServer starting on http://localhost:%d',[Application.Port]));
  Writeln(format('Usage: http://localhost:%d/Druckfreigabe?ID=%d',[Application.Port,12345]));
  Application.Run;
end.

