From 669159a993d2a09cdfba4f1b48be37eb2ae9e521 Mon Sep 17 00:00:00 2001 From: mateusvicente100 Date: Tue, 28 Apr 2020 09:36:56 -0300 Subject: [PATCH] Specific options for multipart/form-data The two new params options is to work with multipar/form-data where is possible add many params and the file (stream) or text (string) types. --- src/core/RESTRequest4D.Request.Params.pas | 19 ++++++++++++++++--- .../RESTRequest4D.Request.Params.Intf.pas | 19 ++++++++++++++++--- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/src/core/RESTRequest4D.Request.Params.pas b/src/core/RESTRequest4D.Request.Params.pas index afd1864..65f8ed1 100644 --- a/src/core/RESTRequest4D.Request.Params.pas +++ b/src/core/RESTRequest4D.Request.Params.pas @@ -12,7 +12,8 @@ TRequestParams = class(TInterfacedObject, IRequestParams) function Clear: IRequestParams; function Add(const AName, AValue: string; const AKind: TRESTRequestParameterKind = TRESTRequestParameterKind.pkQUERY): IRequestParams; overload; function Add(const AName: string; const AValue: Currency; const AKind: TRESTRequestParameterKind = TRESTRequestParameterKind.pkQUERY): IRequestParams; overload; - function Add(const AName: string; const AValue: TStream): IRequestParams; overload; + function AddFile(const AName: string; const AValue: TStream): IRequestParams; + function AddText(const AName, AValue: string; const AContentType: TRESTContentType = TRESTContentType.ctAPPLICATION_JSON): IRequestParams; public constructor Create(const ARESTRequest: TRESTRequest); destructor Destroy; override; @@ -39,7 +40,7 @@ function TRequestParams.Add(const AName: string; const AValue: Currency; const A Result := Self.Add(AName, CurrToStr(AValue), AKind); end; -function TRequestParams.Add(const AName: string; const AValue: TStream): IRequestParams; +function TRequestParams.AddFile(const AName: string; const AValue: TStream): IRequestParams; begin Result := Self; if not Assigned(AValue) then @@ -54,6 +55,18 @@ function TRequestParams.Add(const AName: string; const AValue: TStream): IReques end; end; +function TRequestParams.AddText(const AName, AValue: string; const AContentType: TRESTContentType = TRESTContentType.ctAPPLICATION_JSON): IRequestParams; +begin + Result := Self; + with FRESTRequest.Params.AddItem do + begin + Name := AName; + Value := AValue; + Kind := TRESTRequestParameterKind.pkREQUESTBODY; + ContentType := AContentType; + end; +end; + function TRequestParams.Clear: IRequestParams; var I: Integer; @@ -76,4 +89,4 @@ destructor TRequestParams.Destroy; inherited; end; -end. +end. \ No newline at end of file diff --git a/src/interfaces/RESTRequest4D.Request.Params.Intf.pas b/src/interfaces/RESTRequest4D.Request.Params.Intf.pas index ce2fcdb..f817a1d 100644 --- a/src/interfaces/RESTRequest4D.Request.Params.Intf.pas +++ b/src/interfaces/RESTRequest4D.Request.Params.Intf.pas @@ -56,7 +56,20 @@ interface /// function Add(const AName: string; const AValue: Currency; const AKind: TRESTRequestParameterKind = TRESTRequestParameterKind.pkQUERY): IRequestParams; overload; /// - /// Adds a new parameter. + /// Adds a new file multi part param. + /// + /// + /// Name of the parameter. + /// + /// + /// Parameter value. + /// + /// + /// Returns the instance itself following the fluent API pattern. + /// + function AddFile(const AName: string; const AValue: TStream): IRequestParams; + /// + /// Adds a new text multi part param. /// /// /// Name of the parameter. @@ -67,9 +80,9 @@ interface /// /// Returns the instance itself following the fluent API pattern. /// - function Add(const AName: string; const AValue: TStream): IRequestParams; overload; + function AddText(const AName: string; const AValue: string; const AContentType: TRESTContentType = TRESTContentType.ctAPPLICATION_JSON): IRequestParams; end; implementation -end. +end. \ No newline at end of file