Skip to content

Commit

Permalink
Added a new overload of method body add
Browse files Browse the repository at this point in the history
  • Loading branch information
viniciussanchez committed Oct 30, 2019
1 parent 2bf3aa5 commit 81bb0bb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/core/RESTRequest4D.Request.Body.pas
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ TRequestBody = class(TInterfacedObject, IRequestBody)
function Clear: IRequestBody;
function Add(const AContent: string; const AContentType: TRESTContentType = ctNone): IRequestBody; overload;
function Add(const AContent: TJSONObject; const AOwns: Boolean = True): IRequestBody; overload;
function Add(const AContent: TJSONArray; const AOwns: Boolean = True): IRequestBody; overload;
function Add(const AContent: TObject; const AOwns: Boolean = True): IRequestBody; overload;
public
constructor Create(const ARESTRequest: TRESTRequest);
Expand Down Expand Up @@ -60,6 +61,19 @@ function TRequestBody.Add(const AContent: TObject; const AOwns: Boolean): IReque
end;
end;

function TRequestBody.Add(const AContent: TJSONArray; const AOwns: Boolean): IRequestBody;
begin
Result := Self;
if FRESTRequest.Method = TRESTRequestMethod.rmGET then
raise Exception.Create(NO_CONTENT_SHOULD_BE_ADDED);
if Assigned(AContent) then
begin
Self.Add(AContent.ToString, ctAPPLICATION_JSON);
if AOwns then
AContent.Free;
end;
end;

function TRequestBody.Clear: IRequestBody;
begin
Result := Self;
Expand Down
13 changes: 13 additions & 0 deletions src/interfaces/RESTRequest4D.Request.Body.Intf.pas
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,19 @@ interface
/// Adds content to the body of the request.
/// </summary>
/// <param name="AContent">
/// Content to be added in JSON array format.
/// </param>
/// <param name="AOwns">
/// Indicates who owns JSON.
/// </param>
/// <returns>
/// Returns the instance itself following the fluent API pattern.
/// </returns>
function Add(const AContent: TJSONArray; const AOwns: Boolean = True): IRequestBody; overload;
/// <summary>
/// Adds content to the body of the request.
/// </summary>
/// <param name="AContent">
/// Object that must be serialized.
/// </param>
/// <param name="AOwns">
Expand Down

0 comments on commit 81bb0bb

Please sign in to comment.