anchor.diff:  procedure Register;
   
   implementation
  +
  +uses
  +    MARS.Client.Resource
  +  , MARS.Client.Resource.JSON
  +  , MARS.Client.Resource.Stream
  +  , MARS.Client.Application
  +;
   
   procedure Register;
   begin
  
positive.code: 
      property Request: TIdHTTPRequest read GetRequest;
      property Response: TIdHTTPResponse read GetResponse;
    published
      property MARSEngineURL: string read FMARSEngineURL write FMARSEngineURL;
      property ConnectTimeout: Integer read GetConnectTimeout write SetConnectTimeout;
  
negative.code:   FHttpClient.ReadTimeout := Value;
  end;
  
  class function TMARSClient.GetAsString(const AEngineURL, AAppName,
    AResourceName: string; const APathParams: TArray<string>;
    const AQueryParams: TStrings; const ASilentMode: Boolean): string;
  var
    LClient: TMARSClient;
    LResource: TMARSClientResource;
    LApp: TMARSClientApplication;
    LIndex: Integer;
    LFinalURL: string;
  begin
    try
      LClient := TMARSClient.Create(nil);
      try
        LClient.MARSEngineURL := AEngineURL;
        LApp := TMARSClientApplication.Create(nil);
        try
          LApp.Client := LClient;
          LApp.AppName := AAppName;
          LResource := TMARSClientResource.Create(nil);
          try
            LResource.Application := LApp;
            LResource.Resource := AResourceName;
  
            LResource.PathParamsValues.Clear;
            for LIndex := 0 to Length(APathParams)-1 do
              LResource.PathParamsValues.Add(APathParams[LIndex]);
  
            if Assigned(AQueryParams) then
              LResource.QueryParams.Assign(AQueryParams);
  
            LFinalURL := LResource.URL;
            Result := LResource.GETAsString();
          finally
            LResource.Free;
          end;
        finally
          LApp.Free;
        end;
      finally
        LClient.Free;
      end;
    except on E:Exception do
      begin
  //      Logger.LogWarning('GetAsString exception: [%s] %s, Engine: [%s], App: [%s], Resource: [%s], URL: [%s]'
  //        , [E.ClassName, E.Message, AEngineURL, AAppName, AResourceName, LFinalURL]);
        if not ASilentMode then
          raise E;
      end;
    end;
  end;
  
  class function TMARSClient.GetJSON<T>(const AEngineURL, AAppName,
    AResourceName: string; const APathParams: TArray<string>;
    const AQueryParams: TStrings; const ASilentMode: Boolean;
    const AIgnoreResult: Boolean): T;
  var
    LClient: TMARSClient;
    LResource: TMARSClientResourceJSON;
    LApp: TMARSClientApplication;
    LIndex: Integer;
    LFinalURL: string;
  begin
    Result := nil;
    try
      LClient := TMARSClient.Create(nil);
      try
        LClient.MARSEngineURL := AEngineURL;
        LApp := TMARSClientApplication.Create(nil);
        try
          LApp.Client := LClient;
          LApp.AppName := AAppName;
          LResource := TMARSClientResourceJSON.Create(nil);
          try
            LResource.Application := LApp;
            LResource.Resource := AResourceName;
  
            LResource.PathParamsValues.Clear;
            for LIndex := 0 to Length(APathParams)-1 do
              LResource.PathParamsValues.Add(APathParams[LIndex]);
  
            if Assigned(AQueryParams) then
              LResource.QueryParams.Assign(AQueryParams);
  
            LFinalURL := LResource.URL;
            LResource.GET();
  
            Result := nil;
            if not AIgnoreResult then
              Result := LResource.Response.Clone as T;
          finally
            LResource.Free;
          end;
        finally
          LApp.Free;
        end;
      finally
        LClient.Free;
      end;
    except on E:Exception do
      begin
  //      Logger.LogWarning('GetJSON exception: [%s] %s, Engine: [%s], App: [%s], Resource: [%s], URL: [%s]'
  //        , [E.ClassName, E.Message, AEngineURL, AAppName, AResourceName, LFinalURL]);
        if not ASilentMode then
          raise E;
      end;
    end;
  end;
  
  class function TMARSClient.GetStream(const AEngineURL, AAppName,
    AResourceName: string; const ASilentMode: Boolean): TStream;
  begin
    Result := GetStream(AEngineURL, AAppName, AResourceName, nil, nil, ASilentMode);
  end;
  
  class function TMARSClient.GetJSON<T>(const AEngineURL, AAppName,
    AResourceName: string; const ASilentMode: Boolean): T;
  begin
    Result := GetJSON<T>(AEngineURL, AAppName, AResourceName, nil, nil, ASilentMode);
  end;
  
  class function TMARSClient.GetStream(const AEngineURL, AAppName,
    AResourceName: string; const APathParams: TArray<string>;
    const AQueryParams: TStrings; const ASilentMode: Boolean): TStream;
  var
    LClient: TMARSClient;
    LResource: TMARSClientResourceStream;
    LApp: TMARSClientApplication;
    LIndex: Integer;
  begin
    Result := nil;
    try
      LClient := TMARSClient.Create(nil);
      try
        LClient.MARSEngineURL := AEngineURL;
        LApp := TMARSClientApplication.Create(nil);
        try
          LApp.Client := LClient;
          LApp.AppName := AAppName;
          LResource := TMARSClientResourceStream.Create(nil);
          try
            LResource.Application := LApp;
            LResource.Resource := AResourceName;
  
            LResource.PathParamsValues.Clear;
            for LIndex := 0 to Length(APathParams)-1 do
              LResource.PathParamsValues.Add(APathParams[LIndex]);
  
            if Assigned(AQueryParams) then
              LResource.QueryParams.Assign(AQueryParams);
  
            LResource.GET();
  
            Result := TMemoryStream.Create;
            try
              Result.CopyFrom(LResource.Response, LResource.Response.Size);
            except
              Result.Free;
              raise;
            end;
          finally
            LResource.Free;
          end;
        finally
          LApp.Free;
        end;
      finally
        LClient.Free;
      end;
    except on E:Exception do
      begin
  //      Logger.LogWarning('GetStream exception: [%s] %s, Engine: [%s], App: [%s], Resource: [%s]'
  //        , [E.ClassName, E.Message, AEngineURL, AAppName, AResourceName]);
        if not ASilentMode then
          raise E;
      end;
    end;
  end;
  
  class function TMARSClient.PostJSON(const AEngineURL, AAppName,
    AResourceName: string; const APathParams: TArray<string>; const AQueryParams: TStrings;
    const AContent: TJSONValue; const ASilentMode: Boolean): Boolean;
  var
    LClient: TMARSClient;
    LResource: TMARSClientResourceJSON;
    LApp: TMARSClientApplication;
    LIndex: Integer;
  begin
    Result := False;
    try
      LClient := TMARSClient.Create(nil);
      try
        LClient.MARSEngineURL := AEngineURL;
        LApp := TMARSClientApplication.Create(nil);
        try
          LApp.Client := LClient;
          LApp.AppName := AAppName;
          LResource := TMARSClientResourceJSON.Create(nil);
          try
            LResource.Application := LApp;
            LResource.Resource := AResourceName;
  
            LResource.PathParamsValues.Clear;
            for LIndex := 0 to Length(APathParams)-1 do
              LResource.PathParamsValues.Add(APathParams[LIndex]);
  
            if Assigned(AQueryParams) then
              LResource.QueryParams.Assign(AQueryParams);
  
            LResource.POST(
              procedure (AStream: TMemoryStream)
              var
                LWriter: TStreamWriter;
              begin
                LWriter := TStreamWriter.Create(AStream);
                try
                  LWriter.Write(AContent.ToJSON);
                finally
                  LWriter.Free;
                end;
              end
            );
            Result := LClient.Response.ResponseCode = 200;
          finally
            LResource.Free;
          end;
        finally
          LApp.Free;
        end;
      finally
        LClient.Free;
      end;
    except on E:Exception do
      begin
  //      Logger.LogWarning('PostJSON exception: [%s] %s, Engine: [%s], App: [%s], Resource: [%s]'
  //        , [E.ClassName, E.Message, AEngineURL, AAppName, AResourceName]);
        if not ASilentMode then
          raise E;
      end;
    end;
  end;
  
  class function TMARSClient.PostStream(const AEngineURL, AAppName,
    AResourceName: string; const APathParams: TArray<string>;
    const AQueryParams: TStrings; const AContent: TStream;
    const ASilentMode: Boolean): Boolean;
  var
    LClient: TMARSClient;
    LResource: TMARSClientResourceStream;
    LApp: TMARSClientApplication;
    LIndex: Integer;
  begin
    Result := False;
    try
      LClient := TMARSClient.Create(nil);
      try
        LClient.MARSEngineURL := AEngineURL;
        LApp := TMARSClientApplication.Create(nil);
        try
          LApp.Client := LClient;
          LApp.AppName := AAppName;
          LResource := TMARSClientResourceStream.Create(nil);
          try
            LResource.Application := LApp;
            LResource.Resource := AResourceName;
  
            LResource.PathParamsValues.Clear;
            for LIndex := 0 to Length(APathParams)-1 do
              LResource.PathParamsValues.Add(APathParams[LIndex]);
  
            if Assigned(AQueryParams) then
              LResource.QueryParams.Assign(AQueryParams);
  
            LResource.POST(
              procedure (AStream: TMemoryStream)
              begin
                AStream.Size := 0; // reset
                AContent.Position := 0;
                AStream.CopyFrom(AContent, AContent.Size);
              end
            );
            Result := LClient.Response.ResponseCode = 200;
          finally
            LResource.Free;
          end;
        finally
          LApp.Free;
        end;
      finally
        LClient.Free;
      end;
    except on E:Exception do
      begin
  //      Logger.LogWarning('PostStream exception: [%s] %s, Engine: [%s], App: [%s], Resource: [%s]'
  //        , [E.ClassName, E.Message, AEngineURL, AAppName, AResourceName]);
        if not ASilentMode then
          raise E;
      end;
    end;
  end;
  
  
  end.
  