Skip to content

Commit

Permalink
Merge pull request #17 from mateusvicente100/master
Browse files Browse the repository at this point in the history
Specific options for multipart/form-data
  • Loading branch information
viniciussanchez authored Apr 28, 2020
2 parents bd306cf + 669159a commit be7bf53
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
19 changes: 16 additions & 3 deletions src/core/RESTRequest4D.Request.Params.pas
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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;
Expand All @@ -76,4 +89,4 @@ destructor TRequestParams.Destroy;
inherited;
end;

end.
end.
19 changes: 16 additions & 3 deletions src/interfaces/RESTRequest4D.Request.Params.Intf.pas
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,20 @@ interface
/// </remarks>
function Add(const AName: string; const AValue: Currency; const AKind: TRESTRequestParameterKind = TRESTRequestParameterKind.pkQUERY): IRequestParams; overload;
/// <summary>
/// Adds a new parameter.
/// Adds a new file multi part param.
/// </summary>
/// <param name="AName">
/// Name of the parameter.
/// </param>
/// <param name="AValue">
/// Parameter value.
/// </param>
/// <returns>
/// Returns the instance itself following the fluent API pattern.
/// </returns>
function AddFile(const AName: string; const AValue: TStream): IRequestParams;
/// <summary>
/// Adds a new text multi part param.
/// </summary>
/// <param name="AName">
/// Name of the parameter.
Expand All @@ -67,9 +80,9 @@ interface
/// <returns>
/// Returns the instance itself following the fluent API pattern.
/// </returns>
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.

0 comments on commit be7bf53

Please sign in to comment.