anchor.diff:  
    // endpoints
    Self.endpoints := TObjectList<TPTEndpoint>.Create();
  +
  + Self.receiveTimer := TTimer.Create(nil);
  + Self.receiveTimer.Enabled := false;
  + Self.receiveTimer.Interval := _RECEIVE_CHECK_PERIOD_MS;
  + Self.receiveTimer.OnTimer := Self.OnReceiveTimerTick;
   
    // sem doplnit seznam vsech endpointu:
    Self.endpoints.Add(TPTEndpointBlok.Create());
  
positive.code:     endpoints: TObjectList<TPTEndpoint>;
  
      httpServer: TIdHTTPServer;
      readLock:TCriticalSection;
  
      Fcompact:boolean;
  
  
negative.code: 
  procedure TPtServer.httpGet(AContext: TIdContext; ARequestInfo: TIdHTTPRequestInfo;
    AResponseInfo: TIdHTTPResponseInfo);
  var received:TPtReceived;
  begin
   received := TPtReceived.Create();
   try
     AResponseInfo.ContentType := 'application/json; charset=utf-8';
  
     received.AContext := AContext;
     received.ARequestInfo := ARequestInfo;
     received.endpoint := Self.GetEndpoint(ARequestInfo.Document);
  
     if (received.endpoint = nil) then
      begin
       Self.httpSinkEndpoint(AContext, ARequestInfo, received.respJson);
       received.processed := true;
      end else begin
       case (ARequestInfo.CommandType) of
        hcGET: ;
        hcPOST, hcPUT: begin
           if (ARequestInfo.ContentType <> _PT_CONTENT_TYPE) then
            begin
             PTUtils.PtErrorToJson(received.respJson.A['errors'].AddObject, '406', 'Not acceptable',
                                   'S timto content-type si neumim poradit');
             received.processed := true;
            end else begin
             received.reqJson := TJsonObject.ParseFromStream(ARequestInfo.PostStream, TEncoding.UTF8) as TJsonObject;
  
             if (received.reqJson = nil) then
              begin
               PTUtils.PtErrorToJson(received.respJson.A['errors'].AddObject, '400', 'Bad request',
                                     'Navalidni JSON objekt v pozadavku');
               received.processed := true;
              end;
            end;
        end;
       else
        PTUtils.PtErrorToJson(received.respJson.A['errors'].AddObject, '405', 'Method not allowed',
                              'S touto HTTP metodou si neumim poradit');
        received.processed := true;
       end;
  
       if (not received.processed) then
        begin
         Self.receivedLock.Acquire();
         try
           Self.received.Enqueue(received);
         finally
           Self.receivedLock.Release();
         end;
        end;
      end;
   except
     received.Free();
     AResponseInfo.ContentText := '{"errors":["title":"Server general error"]}';
     Exit();
   end;
  
   // Wait for finishing of the command to send response
   while ((not received.processed) and (Self.received <> nil)) do
     Sleep(_RECEIVE_CHECK_PERIOD_MS); // sleep in its own thread
  
   if (Self.receivedLock <> nil) then
     Self.receivedLock.Acquire();
   try
     AResponseInfo.ContentStream := TStringStream.Create();
     AResponseInfo.FreeContentStream := true;
     received.respJson.SaveToStream(AResponseInfo.ContentStream, Self.compact, TEncoding.UTF8);
   finally
     received.Free();
     if (Self.receivedLock <> nil) then
       Self.receivedLock.Release();
   end;
  end;
  
  function TPtServer.GetEndpoint(path:string):TPTEndpoint;
  var endpoint:TPTEndpoint;
  begin
   Result := nil;
   for endpoint in Self.endpoints do
     if (endpoint.EndpointMatch(path)) then
       Exit(endpoint);
  end;
  
  procedure TPtServer.OnReceiveTimerTick(Sender: TObject);
  begin
   Self.ProcessReceivedMessages();
  end;
  
  procedure TPtServer.ProcessReceivedMessages();
  var received:TPtReceived;
  begin
   if (not Assigned(Self.received)) then
     Exit(); // everything is shutting down
  
   receivedLock.Acquire();
  
   try
     while (Self.received.Count > 0) do
      begin
       received := Self.received.Extract();
       try
         case (received.ARequestInfo.CommandType) of
           hcGet: received.endpoint.OnGET(received.AContext, received.ARequestInfo, received.respJson);
           hcPOST: received.endpoint.OnPOST(received.AContext, received.ARequestInfo,
                                            received.respJson, received.reqJson);
           hcPUT : received.endpoint.OnPUT(received.AContext, received.ARequestInfo,
                                           received.respJson, received.reqJson);
         end;
       except
        on Eorig:Exception do
          PTUtils.PtErrorToJson(received.respJson.A['errors'].AddObject, '500', 'Request exception', Eorig.Message);
       end;
  
       received.processed := true;
      end;
   finally
     receivedLock.Release();
   end;
  end;
  
  procedure TPtServer.httpError(AContext: TIdContext; ARequestInfo: TIdHTTPRequestInfo;
  